Reputation: 315
I have a simple question regarding breaks
in ggplot. They are not displayed correctly, and I was wondering if someone could hint me at what am I doing wrong.
Here is an example
df = data.frame(stringsAsFactors = F,
ub_ch = c(
"hand_rh",
"hand_rh",
"hand_rh",
"hand_rh",
"hand_rh",
"hand_rh",
"hand_lf",
"hand_lf",
"hand_lf",
"hand_lf","hand_bh","hand_bh", "shoulder_rh", "shoulder_rh","shoulder_rh","torso_bw")
)
Here the code
#ordering bars depending on the number of counts
theTable <- transform(df,ub_ch = ordered(ub_ch, levels = names( sort(-table(ub_ch)))))
theTable
#graph
g1<-ggplot(theTable,aes(x=ub_ch,fill = ub_ch))+ scale_y_continuous(labels = scales::percent_format(accuracy = 1))+
geom_bar(aes(y = (..count..)/sum(..count..)),position="dodge")+theme_bw()
g2<-g1+theme(panel.background =element_blank(),panel.grid.major = element_blank(),panel.grid.minor = element_blank()) +
scale_color_grey(start=0, end=.6) +
labs(x="Body articulator") +
theme(legend.position="none",axis.title.y = element_blank())
g2
This is the output
I want to have breaks on the y-axis from 0-40% every 5%
I added the part of breaks=seq(0,40, by=5)
to scale_y_continuous
right after labels
but it's not working as I wish.
This is what I get
Upvotes: 0
Views: 805
Reputation: 21297
Try to have more number of breaks as
scale_y_continuous(labels = scales::percent_format(accuracy = 1), n.breaks=8)
Then you will get
Upvotes: 2