r - In ggplot2 - how to ensure geom_errorbar displays bar limits for all points when controlling x-axis with xlim() -
i using ggplot2 produce simple plot of proportion against integer valued predictor. using geom_errorbar display uncertainty each point estimate.
e.g.
require(ggplot2) mydata <- data.frame(my_x = 70:99, my_y = seq(0.7,0.3,length.out=30), my_lower = seq(0.6,0.2,length.out=30), my_upper = seq(0.8,0.4,length.out=30)) ggplot(mydata,aes(x=my_x)) + geom_point(aes(y=my_y)) + geom_errorbar(aes(ymin=my_lower, ymax=my_upper)) + xlim(70,80) for largely aesthetic reasons using xlim() set x-axis limits (as do). removes horizontal lines indicating limits of error bars @ min , max x-values. presume because ggplot2 trying draw line lies outside of plot part (the function phone call prints warnings geom_path missing values).
i clean info of unwanted rows beforehand or include subset statement in ggplot call, sense there is/should cleaner solution when zooming plot. ideas?
bit hacky seems work:
ggplot(mydata,aes(x=my_x)) + geom_point(aes(y=my_y)) + geom_errorbar(aes(ymin=my_lower, ymax=my_upper)) + coord_cartesian(xlim=c(69.5,80.5)) r ggplot2
No comments:
Post a Comment