r - 如何更改图例中的标签?
问题描述
我想将图例中的标签从 1、2、3、4 更改为特定标签,如“稳定低”、“治疗增加”……但它不起作用。有任何想法吗?
我试过了scale_fill_manual
,scale_colour_manual
改变aes
...
# Create dataframe
timepoint=c("baseline", "baseline", "baseline", "baseline",
"nach briefing", "nach briefing", "nach briefing", "nach
briefing",
"session 4", "session 4", "session 4", "session 4")
expectation=c(9.661290, 14.57692, 12.41667, 14.35714, 10.20968, 14.30769,
17.16667, 15.57143, 9.532258, 15.78846, 15.75000, 10.000000)
ci=c(0.436101, 0.79578, 1.41966, 1.23227, 0.51849, 0.91015, 0.97055,
1.1511,
0.467372, 0.70027, 1.58264, 1.260921)
cluster=c(1,2,3,4,1,2,3,4,1,2,3,4)
df.graph <- data.frame(expectation, ci, timepoint, cluster)
df.graph$cluster <- factor(df.graph$cluster) # damit im Graph nach Farbe
getrennt werden kann
cluster <- ggplot(data=df.graph, aes(x=timepoint, y=expectation,
group=cluster, colour=cluster)) +
geom_line(size=1.2, position=position_dodge(0.06)) +
geom_point(size=4.2, position=position_dodge(0.06),
aes(shape=cluster)) +
scale_shape_manual(values=c(15, 16, 17, 18)) + # change shape
of point manually
scale_size_manual(values=c(2,3,4, 10)) +
geom_errorbar(aes(ymin=expectation-ci, ymax=expectation+ci),
width=.3, linetype="solid", position=position_dodge(0.06)) + # pd damit
CI-
Balken etwas verschoben sind
ylab("Treatment expectations (ETS)") +
xlab("") +
scale_y_continuous(limits = c(5, 20), breaks=seq(1, 20, 1)) +
scale_x_discrete(labels=c("baseline", "after briefing", "after
session 4")) +
theme_classic(base_size = 26) +
scale_colour_manual(values=c("#003f5c", "#bc5090", "#ff6361",
"#ffa600")) +
theme(legend.position=c("top"),
legend.text = element_text(size=20, colour = "gray29",
family ="Calibri"),
legend.key.size = unit(1.7, 'lines'),
legend.title=element_blank(),
panel.grid.major = element_blank(), # removes gridlines
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black"),
axis.title.y = element_text(colour = "gray29", family
="Calibri", size=22),
axis.text.x = element_text(colour = "gray29", size=18,
family ="Calibri"), # Achesenbeschriftung x-Achse
axis.text.y = element_text(colour = "gray29", size=18,
family ="Calibri"),
panel.background = element_rect(fill = "transparent",
color = NA), # bg of the panel
plot.background = element_rect(fill = "transparent",
color = NA),
legend.background = element_rect(fill = "transparent",
size = 0),
legend.key = element_rect(fill = 'transparent', color =
NA)) # get rid of legend bg)
实际结果显示数据框中定义的 1、2、3、4。我想在我的传说中有实际的标签。
解决方案
推荐阅读
- excel - 是否有一个公式可以根据当前选项卡上的输入让单元格在另一个选项卡上显示单元格的内容?
- javascript - Aframe glTF 不显示
- php - 两个链接随机php
- flutter - Flutter 调试与发布版本
- javascript - 如何解决typeError,猫鼬?
- asp.net-core-mvc - 如何在多个视图中重用 html 代码?
- sql-server - SQL Server:如何在链接服务器查询中的子查询中使用变量
- javascript - 如何检查 Json Doc 是否具有 Node JS 中的所有必需键
- python - 您如何创建前三个字母为“the”且没有重复的所有单词的列表并排序
- node.js - 如何为使用 passport.js 登录的“已确认”用户添加新条件?