【问题标题】:Add data points in an existing plot in ggplot在 ggplot 的现有图中添加数据点
【发布时间】:2021-09-13 05:27:16
【问题描述】:

我有以下问题:最初我构建了一个涉及四个不同类别数据点的图,如下图所示:

通过以下代码创建:

 Wells = as.factor(xyClust$group)
      my_colors <- c("red", "blue", "magenta","orange",'black')
      p <- ggplot(data = xyClust, aes(x = x, y = y, color = Wells ) )  +
        geom_point(size=6) +
        scale_color_manual(values = my_colors) +
        #scale_discrete_manual(values = my_colors,names="aa") +
        theme_bw()
      p1 <- p +  geom_point(data = laa, aes(x=X, y=Y,color='borders') ) 
      p1

我想要做的是将黑点与剩余的点分开,因为它们代表区域的边界,因此它们不应该出现在侧面颜色栏中。

【问题讨论】:

标签: r ggplot2 colorbar


【解决方案1】:

好的,我找到了答案。我只是将 ggplot 中的细节移到 geom_point 中,如下所示;

my_colors2 <- c("red", "blue", "magenta","orange")
      p2 <- ggplot( )  +
        geom_point(data = xyClust, aes(x = x, y = y, color = Wells),size=6) +
        scale_color_manual(values = my_colors2) +
        theme_bw()
      p3 <- p2 +  geom_point(data = laa, aes(x=X, y=Y) ) +
        labs(x = "x (m)", y = "y (m)") + 
        theme(axis.title.x = element_text(color = "black", size = 14, face = "bold"),
              axis.title.y = element_text(color = "black", size = 14, face = "bold"),
              axis.text.x = element_text(color = "black", size = 14),
              axis.text.y = element_text(color = "black", size = 14) )
      p3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-11
    • 1970-01-01
    相关资源
    最近更新 更多