简体   繁体   中英

Change Y-axis from exponential to integer

I am trying to convert a y-axis of my barplot from exponential to integer. However, the scaling (using scale_y_continuous) won't adjust my plot. u is just a simple dataframe, containing data about people who joined the query. The data frame contains the columns gender, id, zip code and age. Its a dataset with roughly 6500 rows.

I've tried using scale_y_continuous and discrete, it has not worked, though.

p<-ggplot(u, aes(x=gender, y=NROW(gender))) +
  geom_bar(stat="identity", fill="steelblue")+
  theme_minimal()+
  scale_y_discrete(breaks=c(seq(0:6500)))+
  labs(x="Gender",y="Number of Votes")
p

You are setting your y values using nrow(). geom_bar has a "count" stat option for this type of plot:

p<-ggplot(u, aes(gender)) +
  geom_bar(stat="count", fill="steelblue")+
  theme_minimal()+
  labs(x="Gender",y="Number of Votes")
p

Hopefully this also fixes your y-axis issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM