I'm looking for a function allowing me to draw a curve between my points. Actually, my data are a profile concentration of an element (here Nitrogen), and I need to plot a dotted-line which is curved betwwen points. So here is a image of what I want to do with R (I made this profile with Excel
library(ggplot2)
Sample <- c(-1, -3, -5, -7, -9, -11, -13, -15, -17, -19, -21, -23, -25, -27,
-29, -31, -33, -35, -37)
N <- c(0.14, 0.16, 0.09, 0.09, 0.011, 0.09, 0.10, 0.09, 0.11, 0.11, 0.09, 0.09,
0.05, 0.09, 0.09, 0.10, 0.11, 0.11, 0.11)
tab <- data.frame(N, Sample)
ggplot(tab, aes(x=N, y=Sample, c(0, 0.16)), pch=17) +
geom_path(linetype=3, color='#2980B9', size = 0.1) +
geom_point(color='#2980B9', size = 2) +
scale_x_continuous(position = "top", limits=c(0, 0.16)) +
scale_y_continuous(limits=c(-40, 0))
and Here is the plot I obtain
please can you help me?
答案 0 :(得分:3)
One way get smoothed lines instead of straight lines would be to flip x
and y
in your aesthetics, then apply geom_smooth
instead of geom_path
and then flip the coordinates through coord_flip
:
ggplot(tab, aes(x=Sample, y=N, c(0,0.16)),pch=17) +
coord_flip() +
geom_point(color='#2980B9', size = 2) +
geom_smooth(method = "loess", se = FALSE,
span = 0.25, linetype=3,color='#2980B9', size = 0.1)