简体   繁体   中英

generate R plot with X-axis only showing data values

example plot I'm working on plotting some data. Currently trying to get a plot to only have natural numbers on the x-axis. How is that possible? In the example I'm wondering how I would remove the values 1.2 1.4 1.6 1.8

Thanks

I would visualize plots like the example using scale_x_continuous(breaks = c(1,2)) .

x = sample(1:2, 1000, replace = T)
y = sample(1:6, 1000, replace = T)
df = data.frame(x, y)

df %>% 
  ggplot(aes(x = x, y = y)) +
  geom_point() +
  scale_x_continuous(breaks = c(1,2))

This would generate plots like this.

情节

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