[R] ggplot pointrange from other df and missing legend
PIKAL Petr
petr@p|k@| @end|ng |rom prechez@@cz
Mon May 16 13:15:55 CEST 2022
Hallo all
Here are the data from dput
test <- structure(list(Sample = c("A", "A", "A", "A", "A", "A", "B",
"B", "B", "B", "B", "B", "C", "C", "C", "C", "C", "C"), SSAtype = c("one",
"one", "one", "two", "two", "two", "one", "one", "one", "two",
"two", "two", "one", "one", "one", "two", "two", "two"), value =
c(8.587645149,
8.743793651, 8.326440422, 9.255940687, 8.971931555, 8.856323865,
9.650809096, 9.725504448, 9.634449367, 9.69485369, 9.526758476,
10.03758001, 10.76845392, 10.66891602, 10.34894497, 10.76284989,
10.53074081, 11.16464528), SSAmeasuredP = c(8.3, 8.3, 8.3, 8.3,
8.3, 8.3, 9.5, 9.5, 9.5, 9.5, 9.5, 9.5, 11, 11, 11, 11, 11, 11
), identity = c("point", "point", "point", "point", "point",
"point", "point", "point", "point", "point", "point", "point",
"point", "point", "point", "point", "point", "point")), row.names = c(NA,
18L), class = "data.frame")
test.ag <- structure(list(Sample = c("A", "B", "C"), avg = c(8.3, 9.5, 11
), odch = c(0.2, 0.4, 0.3), identity = c("point", "point", "point"
)), row.names = c(NA, 3L), class = "data.frame")
I try to make some relatively simple barplot and I wanted to add points to
it which I somehow did.
library(ggplot2)
p <- ggplot(test, aes(x=Sample, y=value, fill=SSAtype))
p+geom_col(position="dodge")+geom_point(aes(y=SSAmeasuredP, shape=identity),
size=5)+
scale_fill_manual(values=tablePal, name="Calculation\n performed\n according
to",
labels=c("bla", "blabla"))+
guides(fill= guide_legend(override.aes = list(shape=NA)))+
scale_shape_manual(name = "Measured", values=19, labels=NULL)
But instead of points I want to use pointrange with data from other df. I
found some help and all is good except size of the points and missing legend
ggplot()+
geom_col(data=test, aes(x=Sample, y=value, fill=SSAtype), position="dodge")+
scale_fill_manual(values=tablePal, name="Calculation\n performed\n according
to",
labels=c("bla", "blabla"))+
geom_pointrange(data=test.ag, aes(x=Sample, y=avg, ymin=avg-odch,
ymax=avg+odch)) +
guides(fill= guide_legend(override.aes = list(shape=NA)))+
scale_shape_manual(name = "Measured", values=19, labels=NULL)
Although I will try to find some workable way I also would like to ask for
help from R gurus, maybe I overlooked some simple way how to do it.
Best regards
Petr
More information about the R-help
mailing list