gpt4 book ai didi

删除ggplot中的图例之一

转载 作者:行者123 更新时间:2023-12-03 09:10:39 25 4
gpt4 key购买 nike

data = cbind(c("A","B","C","A"), c("John", "Kendra", "Martin", "Steve"), c("12","12","13","14"))
colnames(data) = c("Group", "Name", "Score")
data = as.data.frame(data)
p = ggplot(data, aes(x=Name, y=Score, fill=Name)) + geom_point(pch = 19, aes(col=Group)) + scale_colour_manual(values=c("black", "red", "green"))
print(p)

嘿,这段代码产生两个图例:名称和组。如何摆脱名称的图例?我指的是整个传说,而不仅仅是它的标题。编辑:我自己刚刚弄清楚。你可以这样说:

p = p + guides(fill=FALSE)

最佳答案

我会稍微调整您的示例以适合我

您可以使用theme来修改整个图例,但如果您想将修改限制在单个元素上,请改用guide:

data <- cbind(c("A","B","C","A"), c("John", "Kendra", "Martin", "Steve"), c("12","12","13","14"))
colnames(data) <- c("Group", "Name", "Score")
data <- as.data.frame(data)

p <- ggplot(data, aes(x = Name, y = Score, fill = Name)) +
geom_point(pch = 19, aes(col = Group)) +
scale_colour_manual(values = c("black", "red", "green")) +
guides(fill = FALSE); p

这里有更详细的解释:cookbook for R .

希望这有帮助:)

关于删除ggplot中的图例之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42862873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com