简体   繁体   English

使用X轴生成R图仅显示数据值

[英]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. 目前正试图让图表在x轴上只有自然数。 How is that possible? 怎么可能? In the example I'm wondering how I would remove the values 1.2 1.4 1.6 1.8 在示例中,我想知道如何删除值1.2 1.4 1.6 1.8

Thanks 谢谢

I would visualize plots like the example using scale_x_continuous(breaks = c(1,2)) . 我会使用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. 这会产生这样的情节。

情节

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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