Hi All,
I'm a beginner with ggplot and I have a simple but specific problem. Unfortunately, I cannot find a simple solution on any website. May I kindly ask for your help?
I would like to create a ggplot line plot with two y axis, with one y on the left side and one y on the right side. However, all options I find on the internet is with scaling the variable. I would like to use my variable just as it is, without scaling, also one of the variables has some missing values. Thus, for me, it seems quite complicated to create the graph. For example, this is the data:
(the values are from the Evanno method following a Structure analysis, if it is helpful for someone)
k(x_axis) elpdmean(first_y_axis,_left_side) elpdmin(error_for_first_y_axis) elpdmax(error_for_first_y_axis) deltaK(second_y_axis,_right_side)
1 -7993.02 -7993.2 -7992.8 NA
2 -8929.45 -10160.1 -8478.3 5.02022896057085
3 -7464.6 -7603.1 -7387.5 27.4350590318052
4 -7769.82 -9053.1 -7403.8 1.29238220974692
5 -7379.98 -7560.3 -7304.1 4.92354930446963
6 -7450.48 -8753.1 -7262.5 0.123848798857256
7 -7463.89 -8221.6 -7245 NA
Here is the R script:
k<-c(1,2,3,4,5,6,7)
lkmean<-c(-7993.02,-8929.45,-7464.6,-7769.82,-7379.98,-7450.48,-7463.89)
lkmin<-c(-7993.2,-10160.1,-7603.1,-9053.1,-7560.3,-8753.1,-8221.6)
lkmax<-c(-7992.8,-8478.3,-7387.5,-7403.8,-7304.1,-7262.5,-7245.0)
deltak<-c(NA,5.02022896057085,27.4350590318052,1.29238220974692,4.92354930446963,0.123848798857256,NA)
test.data<-data.frame(k,lkmean,lkmin,lkmax,deltak)
library(ggplot2)
p<-ggplot(test.data, aes(k, lkmean)) +
geom_line()
I appreciate all the suggestions and helps :) Thank you!