简体   繁体   中英

Trying to replicate excel graph in R

Looking for help making a graph in R with example data below. I am trying to make the same graph as in the picture but in R. When I try to replicate it the blue line becomes vertical and not is not horizontal despite the data. The orange line plots ok though. The larger dataset has multiple stations so thats why I also include facets in my code.

在此处输入图片说明

(R graph uses the whole data set hence the curves do not match)

Here is my R code as well. Can someone please help? Thank you.

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

you should take "group=station" from the aes();

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()

yields:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM