r - Reduce space between axis and geom -
i have plot looks this:
how can remove space between laft edge of line , y axis without cutting off directlabels?
the code:
library(ggplot2) library(scales) labs <- c("special ed., charter school", "gen. ed., charter school", "special ed., public school", "gen. ed., public school") pot <- data.frame(engagement = c(643, 793, 590, 724, 735, 928, 863, 662), classroom = rep(rep(c("special ed.", "gen. ed."), each = 2), 2), gender = factor(rep(c("male", "female"), 4), levels = c("male", "female")), school = rep(c("charter", "public"), each = 4), id = factor(rep(1:4, each = 2)), labs = factor(rep(labs, each=2), levels=labs) ) library(directlabels) xout <- ggplot(pot, aes(y = engagement, x = gender, group = id)) + geom_line(aes(color=labs), size=2) + theme_classic() + scale_x_discrete(expand = c(.1, .3)) + scale_color_hue(l=40) + theme(text = element_text(size=22)) direct.label(xout, list('last.qp', cex=1.35))
workaround add empty level gender.
pot$gender<-factor(pot$gender,levels=c("male","female",""))
then in scale_x_discrete()
use drop=false
show level. can change expand=
values.
+ scale_x_discrete(expand = c(0.01, 0.01),drop=false)
other possibility use gender
numeric , scale_x_continuous()
set limits=
, provide breaks=
, labels=
correct labeling again.
xout <- ggplot(pot, aes(y = engagement, x = as.numeric(gender), group = id)) + geom_line(aes(color=labs), size=2) + theme_classic() + scale_x_continuous(expand=c(0,0),"gender",breaks=c(1,2), labels=c("male","female"),limits=c(0.95,4)) + scale_color_hue(l=40) + theme(text = element_text(size=22))
Comments
Post a Comment