简体   繁体   中英

Setting plot min and max

I'm trying to plot a data set in R and am wanting to set min and max for my y-axis. It isn't showing 0, and I want it to. I've had to use a scale_y_log10 and am wondering how I add limits to this. I did try adding limits = c(?,?) but to no avail.

Any help would be appreciated.

Here's my code for reference if needed

ggplot(data = rc_data, aes(x = t, y = Vc))+
  geom_point()+ 
  geom_smooth(method = lm, se = FALSE) +
  labs(x = "Time (sec)",
       y = "Voltage (V) , Log Scale") +
  ggtitle("Drop of Voltage of a Capacitor")+
  theme_bw()+
  scale_x_continuous(breaks = round(seq(min(rc_data$t), max(rc_data$t), by = 5),1)) +
  scale_y_log10(breaks = round(seq(0, max(rc_data$Vc)+0.5, by = 0.2),1))

Calculate your own log10 , then plot, after that we can set limits to yaxis , see example:

library(ggplot2)

# example data
df1 <- mtcars[ , c("mpg", "disp")]
df1$disp_log10 <- log10(df1$disp)

ggplot(data = df1, aes(mpg, disp_log10))+
  geom_point()+ 
  geom_smooth(method = lm, se = FALSE) +
  scale_y_continuous(limits = c(0, max(df1$disp_log10)))

在此处输入图片说明

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