【问题标题】:generate R plot with X-axis only showing data values生成 R 图,X 轴仅显示数据值
【发布时间】:2019-09-05 22:25:06
【问题描述】:

example plot 我正在绘制一些数据。目前试图让一个图在 x 轴上只有自然数。这怎么可能?在示例中,我想知道如何删除值 1.2 1.4 1.6 1.8

谢谢

【问题讨论】:

    标签: r data-science


    【解决方案1】:

    我会使用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))
    

    这会生成这样的图。

    【讨论】:

    • 为了概括这一点,我会将breaks = c(1,2) 替换为breaks=unique(as.integer(x))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-31
    • 2022-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多