ggplot2 - Changing discrete axis tick marks in ggplot, R -
i creating plot shows confidence intervals of 2 models each factor. if factors 'a', 'b', 'c', have 6 confidence intervals ci1.a, ci2.a, ci1.b, ci2.b, ci1.c, ci2.c. using simple forest plot want y-axis labels a, b, c, in middle of ci1.a , ci2.a. how can rearrange tick marks make them appear in middle of 2 factors?
here toy example. have 49 factors need way able read of labels.
factors <- c('a1', 'a2', 'b1', 'b2', 'c1', 'c2') y <- c(1:6) yhi <- y + .5 ylo <- y - .5 df <- data.frame(factors = factors, y = y, yhi =yhi, ylo = ylo) ggplot(df, aes(x=factors, y=y, ymin=ylo, ymax=yhi)) + geom_linerange() + coord_flip()
i think best bet change data frame factor , model separate columns.
that way, ticks automatically come out way want them. default, geom_linerange()
position lineranges 2 different models on top of each other, can change position=position_dodge(width=<<number>>)
. used 0.1 put lines not quite on top of each other. increase value if want them farther apart. think had in mind width=1
.
#load package require(ggplot2) #make toy data models <- rep(c(1,2), 3) factors <- c('a', 'a', 'b', 'b', 'c', 'c') df <- data.frame(factors=factors, models=factor(models), y=1:6, yhi=1:6+0.5, ylo=1:6-0.5) #do graphing quartz(height=3, width=6) ggplot(df, aes(x=factors, y=y, ymin=ylo, ymax=yhi, color=models)) + geom_linerange(size=2, position=position_dodge(width=0.1)) + coord_flip() + theme_bw() quartz.save('so_29545579.png')