试图在R中复制excel图

时间:2017-08-24 17:31:29

标签: r ggplot2 linegraph

寻找帮助在R中制作图表,并提供以下示例数据。我试图制作与图片中相同的图形,但在R中。当我尝试复制它时,蓝线变为垂直而不是水平,尽管有数据。橙色线虽然很好。较大的数据集有多个工作站,这就是我在代码中也包含facet的原因。

enter image description here

(R图使用整个数据集,因此曲线不匹配)

这也是我的R代码。有人可以帮忙吗?谢谢。

ggplot(TS, aes(X, Y, group=Station, colour=factor(Type))) + 
  facet_grid(~Station) + geom_line(size = 1) + xytheme 


   Y    X   Type    Station
2.13    0   Blue    1
2.13    50  Blue    1
2.13    100 Blue    1
3.67    0   Orange  1
3.17    10  Orange  1
2.94    15  Orange  1
1.58    20  Orange  1
1.25    35  Orange  1
1.02    46  Orange  1
0.99    65  Orange  1
0.52    74  Orange  1
0.2     82  Orange  1
0.1     91  Orange  1
0.22    100 Orange  1

1 个答案:

答案 0 :(得分:1)

你应该从aes();

取“group = station”
library(ggplot2)
library(ggthemes)        
TS <- data.frame(y=c(2.13,2.13,2.13,3.67,3.17,2.94,1.5,1.2,1.0,0.99,0.52,0.2,0.1),
               x=c(0,50,100,0,10,15,20,35,46,65,74,82,91),
               type=c("blue","blue","blue", "orange","orange","orange","orange",
                      "orange","orange","orange","orange","orange","orange"),
               station=1)

    ggplot(TS, aes(x, y, colour=factor(type))) + geom_line(size = 1) + theme_excel()

的产率:

enter image description here