【问题标题】:changing colour or thickness of one point of data set in ggplot2改变ggplot2中一个数据集的颜色或厚度
【发布时间】:2015-03-16 23:53:31
【问题描述】:

我目前正在绘制我的数据集的影响。

我在我的数据集中添加了一个额外的列 (BP),并且能够按船期为图表着色。

      BoatPhs      fit       se      lower     upper        BP
1         Before 3.685875 0.3287521 3.038621 4.333130     Before
2   After0-20NTA 3.317189 0.6254079 2.085872 4.548506  After0-20
3   After0-20TAA 5.579384 0.5696270 4.457890 6.700878  After0-20
4   After0-20TAP 3.932360 0.4304098 3.084960 4.779760  After0-20
5  After20-40NTA 4.522714 0.7771793 2.992586 6.052842 After20-40
6  After20-40TAA 4.505207 0.5500699 3.422217 5.588196 After20-40
7  After20-40TAP 3.602183 0.3880538 2.838174 4.366192 After20-40
8    ApproachNTA 4.039599 0.5688482 2.919638 5.159560   Approach
9    ApproachTAA 4.421112 0.5176408 3.401969 5.440255   Approach
10   ApproachTAP 4.497809 0.3978328 3.714547 5.281071   Approach
# Speed plot
Spdplot <- ggplot(y, aes(x=BoatPhs, y=fit, colour=BP, ymax=max(fit)*1.05)) + geom_point(position = position_dodge(width = 0.5, height = 0), size = 2) + geom_errorbar(aes(ymin=fit-se, ymax=fit+se), position = position_dodge(width = 0.5, height = 0), width = 0.5) +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black"))+

#run Spdplot
Spdplot

#sets x values in results order + relables x + y axes + changes colours
Spdplot + scale_x_discrete(limits=c("Before","ApproachNTA","ApproachTAA","ApproachTAP","After0-20NTA","After0-20TAA","After0-20TAP", "After20-40NTA","After20-40TAA","After20-40TAP")) + 
  xlab("Boat Phase") + ylab("Log of Group Travel Speed") + 
  annotate("text", x=6, y=6.2, label="***") +
  annotate("text", x=4, y=4.95, label="*") + 
  theme(axis.title.x = element_text(vjust=-0.5), axis.title.y = element_text(vjust= 1), axis.text.x = element_text(size=12), axis.text.y = element_text(size=12)) +
  theme(legend.title = element_blank()) + 
  scale_colour_manual(values=c("#999999","#666666","#CCCCCC","#000000"), 
                      breaks=c("Before", "Approach", "After0-20", "After20-40"),
                      labels=c("Before", "Approach", "After0-20", "After20-40"))

我想做的是能够使前一阶段的点和误差条更粗更粗。有谁知道如何改变这一点的细节?还是多个不同的点?我知道如何为多个组更改它们,但我只想让一个点比其他点更突出一点。

干杯

【问题讨论】:

    标签: r colors ggplot2


    【解决方案1】:

    如果您首先将另一个变量添加到 y 并只制作之前的阶段 T,您可以有条件地对其进行加粗、加粗和着色。下面的代码仅显示颜色。

    y$bold <- c(T, rep(F, 9))
    

    这是只用红色绘制的情节:

    Spdplot <- ggplot(y, aes(x=BoatPhs, y=fit, colour=BP, ymax=max(fit)*1.05)) +
      geom_point(position = position_dodge(width = 0.5, height = 0), size = 2) +
      geom_errorbar(aes(ymin=fit-se, ymax=fit+se, color = ifelse(y$bold == T, "green", "black")), position = position_dodge(width = 0.5, height = 0),
                    width = 0.5) +
      theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
            panel.background = element_blank(), axis.line = element_line(colour = "black"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-14
      • 1970-01-01
      • 1970-01-01
      • 2013-10-26
      • 1970-01-01
      • 2020-08-25
      相关资源
      最近更新 更多