【问题标题】:Removing some point from geom_point ggplot2从 geom_point ggplot2 中删除一些点
【发布时间】:2019-03-02 03:07:50
【问题描述】:

假设我有一些名为“坐标”的坐标。我绘制了这些坐标,我想用点来表示,所以我使用 geom_points:

coordinates <- tibble(x = x_coords, y = y_coords)
ggplot(coordinates, aes(x = x, y = y)) + geom_point()

我将如何更改 geom_point() 以便它总是从图中的第一个坐标中删除点,例如放置 geom_point() + geom_line()

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    从您的数据集中过滤这些点:

    coordinates <- tibble(x = x_coords, y = y_coords)
    
    ggplot(coordinates, aes(x = x, y = y)) +
      geom_point(data = coordinates %>% filter(row_number() > 1)) +
      geom_line()
    

    【讨论】:

    • 我的问题可能不是很清楚,但我的意思是保留坐标,但在放置时删除坐标中的点,例如geom_point() + geom_line()
    • @RoosterRooney 看到我的更新。使用geom_ 层的data 参数
    • 如果您想为其他 geom_() 调用保留数据点,请使用 aes(color = ifelse(x == my_value_x &amp; y == my_value_y, NA, "red")) 进行 geom_point 美学。
    • @JackBrookes 感谢您的帮助!现在明白了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-13
    相关资源
    最近更新 更多