This question is related to Multiple plots in R by connecting two points using ggplot2 I would like to add one point (mean row) in each line. The data set is
> dput(mydata)
structure(list(x1m1 = c(0.5, 1, 0.6), x1m2 = c(0.2, 1.5, 0.25
), x1m3 = c(0.5, 1.25, 1), x2m1 = c(0.24, 0.98, 0.7), x2m2 = c(0.1,
1.4, 0.8), x2m3 = c(1, 2, 0.6)), class = "data.frame", row.names = c("LCL",
"UCL", "mean"))
> mydata
x1m1 x1m2 x1m3 x2m1 x2m2 x2m3
LCL 0.5 0.20 0.50 0.24 0.1 1.0
UCL 1.0 1.50 1.25 0.98 1.4 2.0
mean 0.6 0.25 1.00 0.70 0.8 0.6
And reduce the gap between X1
and X2
. Any help is appreciated
To add a point to lien ranges, use geom_pointrange
. But the data must first be transposed and prepared.
Note that in the posted data, the mean value of x2m2
is not between LCL
and UCL
.
library(dplyr)
library(ggplot2)
mydata %>% t() %>%
as.data.frame() %>%
mutate(model = row.names(.)) %>%
mutate(id = substr(model, 1, 2), model = substring(model, 3)) %>%
ggplot(aes(model, mean, colour = model)) +
geom_pointrange(aes(ymin = LCL, ymax = UCL)) +
facet_wrap(~ id)
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.