尝试复制R中的Excel图表

问题描述:

寻找使用下面的示例数据在R中创建图表的帮助。我试图制作与图片中相同的图形,但是在R中。当我尝试复制它时,蓝线变为垂直,尽管有数据,但不是水平的。橙色的线虽然可以。较大的数据集有多个站点,这就是为什么我在代码中也包含方面的原因。尝试复制R中的Excel图表

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 
+0

取出'组= Station'和'facet_grid',你只能有一个站所以它是没有必要的。 – tkmckenzie

+0

我有文中提到的多个电台.... – user5792796

您应该从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

+0

固定!谢谢Elio Diaz! – user5792796

+1

如果答案对您有帮助,请将其投票并接受。 – neilfws