简体   繁体   中英

Keepin the x and y scale to max values with defined intervals in ggplot in R

I have a set of data frame values and have plotted it with the help of ggplot the code I have is as follows:

ggplot(lung_dfdsa, aes(x=z_lung_con, y=lung_dsa)) + geom_point(shape=21, colour = "blue")+ scale_x_continuous(breaks = seq(0,20,2)) + scale_y_continuous(breaks = seq(0,20,by= 2)) +geom_smooth(method=lm)+ labs(x = "Measured lung expression values", y = "Estimated lung expression values") + theme_bw() + theme( panel.grid.major = element_blank(),panel.grid.minor = element_blank(),panel.border = element_rect(colour = "black"))

This code creates a graph with the axis limits upto 14 because there is data only upto that, but what I would want is to have the max limit upto 20 with the intervals I have defined even if there aren't any values in the dataset upto that range. Is that possible?

You can use expand_limits . See http://docs.ggplot2.org/current/expand_limits.html

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