i using geom_hline(yintercept = log(2000), linetype = "dotdash") in ggplot2 add horizontal line @ y = log(2000) in plot (attached below).
what want display legend "log(2000)" @ left side of y axis corresponding dash line. ideas?

the r code of plot given below:
library(ggplot2); library(scales) set.seed(10) varx <- rep(c("group1", "group2"), each = 3) vary <- rep(c("a", "b", "c"), 2) poi <- sample(20:30, 6) upper <- sample(40:50, 6) lower <- sample(1:10, 6) dat <- data.frame(varx, vary, poi, upper, lower) dat # varx vary poi upper lower #1 group1 25 43 2 #2 group1 b 23 42 6 #3 group1 c 29 45 3 #4 group2 30 50 4 #5 group2 b 20 44 1 #6 group2 c 21 47 10 pp <- ggplot(dat, aes(colour = varx, y = poi, x = vary)) limits <- aes(ymax = upper, ymin = lower) pp + geom_point(aes(shape=varx), position = position_dodge(0.3), size = 2) + ## dodge make lines not stack upon each other geom_errorbar(limits, size = 1, width = 0.15, position = position_dodge(0.3)) + theme_bw() + ## rid of grey background geom_hline(yintercept = log(2000), linetype = "dotdash") + coord_cartesian(ylim = c(1, 60)) + scale_shape_manual(values = c(17, 19)) + theme(legend.justification= c(1, 0), legend.position = c(1, 0.75), legend.key = element_blank(),## rid of legend box legend.title = element_blank(), legend.text = element_text(size = 10, face = "bold"), legend.background = element_rect(fill=alpha(0.0001))) + labs(x = null, y = null)
building on @lukea's comment
pp + scale_y_continuous(breaks = sort(c(log(2000), seq(0, 60, 10))),labels=c(0,"log(2000)",seq(10,60,10))) 
Comments
Post a Comment