我有一个情节(下面粘贴的示例代码),我试图通过系列信息的自有标签添加.而不是绘制"p1s1""p1s2""p3s4",我想"治疗1""治疗2""治疗3".我使用了levels(series_id)来获取唯一的系列名称,并使用查找表来获取描述.(我认为这会按照他们绘制的顺序得到它们吗?)并且我在一个名为treatment_descriptions的向量中有这些描述.
从文档我认为我应该在这里使用一个比例,但我无法弄清楚哪一个,或如何做到这一点.类似于:scale_something(name ="Treatment Descriptions",breaks = NULL,labels = treatment_descriptions,formatter = NULL)?但这应该去哪里?
library(ggplot2)
# Create a long data.frame to store data...
growth_series = data.frame ("read_day" = c(0, 3, 9, 0, 3, 9, 0, 2, 8),
"series_id" = c("p1s1", "p1s1", "p1s1", "p1s2", "p1s2", "p1s2", "p3s4", "p3s4", "p3s4"),
"mean_od" = c(0.6, 0.9, 1.3, 0.3, 0.6, 1.0, 0.2, 0.5, 1.2),
"sd_od" = c(0.1, 0.2, 0.2, 0.1, 0.1, 0.3, 0.04, 0.1, 0.3),
"n_in_stat" = c(8, 8, 8, 8, 7, 5, 8, 7, 2)
)
> # …Run Code Online (Sandbox Code Playgroud) 尝试使用ggplot更改图例中图例中的标签名称时遇到问题。
我来阅读有关Cookbook for R主题的一些教程,以及本论坛中有关同一主题的问题(如何在ggplot2中手动更改图例中的键标签),以及更多内容。我写这篇文章的原因是因为我无法理解ggplot函数的运行情况,该函数使scale_fill_discrete()无法正常工作,而在其他示例中却如此。
我的数据框是这样的:
x w t
1 0.8972208 A 0
2 0.8312684 A 1
3 0.7504638 A 2
4 0.6563472 A 3
5 0.5764883 A 4
6 0.5224609 A 5
7 0.8972208 B 0
8 0.8456315 B 1
9 0.7674353 B 2
10 0.6689723 B 3
11 0.6114414 B 4
12 0.5381668 B 5
13 0.8983253 C 0
14 0.7878405 C 1
15 0.6955420 C 2
16 0.6179749 …Run Code Online (Sandbox Code Playgroud)