简体   繁体   中英

ggplot2 x-axis tick spacing

I have this plot currently where the 4 x-axis ticks are evenly spaced apart:

https://i.stack.imgur.com/VXfQt.png

The spacing between 26, 27, and 28 degrees is fine but I want a larger gap between 22.5 and 26 degrees because it is a 3.5 degree difference instead of just one degree.

Here is my current code:

Line = ggplot(grouped_data, aes(temp, pct.male, group=sire, color=sire)) + 
  geom_line(size=1.3) +
  geom_point(aes(shape=sire), size=2.5) +
  xlab("Incubation temperature (°C)") +
  ylab("Sex ratio (proportion male)") +
  ggtitle("Sex ratio reaction norms as a function of incubation temperature (2017 data only)") +
  scale_shape_manual(values=seq(0,15))

Line

Any help with solving this problem would be much appreciated! Thank you!

Your x-axis is being treated as categorical. Convert the temp column to numeric so it will be treated as numeric:

grouped_data$temp = as.numeric(as.character(grouped_data$temp))

You may want to specify the same axis breaks,

...your plotting code... + 
  scale_x_continuous(breaks = unique(grouped_data$temp))

If this doesn't work or you need more help, please share a reproducible sample of data. dput(grouped_data) is a great way to share data because it's copy/pasteable.

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