My data basically looks like this:
Populations alpha SE Z sample color
Pop1 0.029000 0.003589 8.116 9 red
Pop2 0.031868 0.003498
How about this?
I'm still new to R (and SO) but afaik aes(colour=xxx)
doesn't set the actual colour, it determines the scale_color_xxx
to apply. You seem to want the colour to change with each Populations2
, so change the colour series based on that, if that makes sense.
Sorry, don't have enough rep (yet) to post an image of the output I get as well.
txt <- "Populations alpha SE Z sample color
Pop1 0.029000 0.003589 8.116 9 red
Pop2 0.031868 0.003498 8.231 9 red
Pop3 0.028969 0.003765 7.942 8 blue
Pop4 0.030651 0.003479 8.792 10 green"
tbl <- read.table(text = txt, header = TRUE)
require(ggplot2)
tbl$Populations2 <- factor(tbl$Populations, as.character(tbl$Populations))
ggplot(tbl, aes(y = Populations2,
x = alpha,
xmin = alpha - SE,
xmax = alpha + SE,
label = Populations2,
colour = Populations2
)) +
geom_point(colour = "black") +
geom_text(hjust = 1.2) +
theme_classic() +
theme(axis.title = element_blank(),
axis.ticks = element_blank(),
axis.text.y = element_blank(),
legend.position = "none") +
geom_errorbarh(height = .1) +
scale_color_manual(values = as.character(tbl$color))