更改 ggplot 散点图的颜色、填充和形状

问题描述 投票:0回答:0

我正在尝试创建一个散点图,其中 x 轴为第 1 周,y 轴为第 2 周。我想让那些住在农田附近的人填充一种颜色,而那些住在远离农田的人用另一种颜色填充空心符号。我也想把那些没有跟进的干预做成不同的符号(比如三角形)

我已经想出如何改变近场/远场的颜色以及如何根据那些没有遵循干预的人改变符号,但我这辈子都想不出如何改变近场的填充-现场参与者。

我已尝试使用 geom_point 和 scale_shape_manual 进行各种迭代,但无法正常工作。这是我尝试过的一些代码:

    geom_point(aes(shape=exclusion, fill=Field), size=3) +
      scale_x_continuous(trans = "log", breaks = c(0, 0.1, 0.5, 1.0), 
       limits = c(NA, 1.2)) +
      scale_y_continuous(trans = "log", breaks = c(0, 0.1, 0.5, 1.0), 
        limits = c(NA, 1.2)) +
      guides(colour = guide_legend(title="Residenital Proximity\nto 
        Agricultural Field")) + 
      scale_color_discrete(labels = c("Far Field", "Near Field")) + 
      labs(y="Urinary glyphosate concentration (ug/L) conventional 
        week", x="Urinary glyphosate (ug/L) organic week"
      geom_abline(slope=1, intercept=0) +
        theme_minimal() + 
        theme(strip.text = element_blank (),
           legend.title = element_blank(),
           legend.position = "none")  

我也试过:

    ggplot(data=data_scatter, aes(x=result_org, y=result_conv)) + 
      geom_point(aes(color=factor(Field), 
                     shape=factor(excl_3))) + 
      scale_shape_manual(values=c(1, 2, 16, 17)) + 
      scale_x_continuous(trans = "log", breaks = c(0, 0.1, 0.5, 1.0), 
       limits = c(NA, 1.2)) +
      scale_y_continuous(trans = "log", breaks = c(0, 0.1, 0.5, 1.0), 
       limits = c(NA, 1.2)) +
      guides(colour = guide_legend(title="Residenital Proximity\nto 
        Agricultural Field")) + 
      labs(y="Urinary glyphosate concentration (ug/L) conventional 
        week", x="Urinary glyphosate concentration (ug/L) organic 
        week") +
      geom_abline(slope=1, intercept=0) +
      theme_minimal() 

当我这样做时,我得到以下图像,其中颜色/形状不同,但没有填充1

r ggplot2 scatter-plot geom-point
© www.soinside.com 2019 - 2024. All rights reserved.