R 删除ggplot2图例将从绘图中删除整个数据
这里有2维数值数组R 删除ggplot2图例将从绘图中删除整个数据,r,ggplot2,R,Ggplot2,这里有2维数值数组数据集和1维数值标签数组clustring。然后我用以下代码绘制它: s = data.frame(x = dataset[,1], y = dataset[,2]) p = ggplot(s, aes(x, y)) p + geom_point(aes(colour = factor(clustering))) 其中显示了美丽的图片: 现在我想完全删除图例,因此我找到了可能的解决方案: # Remove legend for a particular aesth
数据集
和1维数值标签数组clustring
。然后我用以下代码绘制它:
s = data.frame(x = dataset[,1], y = dataset[,2])
p = ggplot(s, aes(x, y))
p + geom_point(aes(colour = factor(clustering)))
其中显示了美丽的图片:
现在我想完全删除图例,因此我找到了可能的解决方案:
# Remove legend for a particular aesthetic (fill)
p + guides(fill=FALSE)
# It can also be done when specifying the scale
p + scale_fill_discrete(guide=FALSE)
# This removes all legends
p + theme(legend.position="none")
但这些命令都没有用。它显示的是空绘图:
那么如何从绘图中删除图例呢?试试以下方法:
library(ggplot2)
s = data.frame(x = rnorm(20), y = rnorm(20), clustering = rep(c(1, 2), 10))
p <- ggplot(s, aes(x, y))+
guides(fill=FALSE)+
geom_point(aes(colour = factor(clustering)))+
scale_fill_discrete(guide=FALSE)+
theme(legend.position="none")
p
但是我写的方式是更常见的R格式。试试这个:
library(ggplot2)
s = data.frame(x = rnorm(20), y = rnorm(20), clustering = rep(c(1, 2), 10))
p <- ggplot(s, aes(x, y))+
guides(fill=FALSE)+
geom_point(aes(colour = factor(clustering)))+
scale_fill_discrete(guide=FALSE)+
theme(legend.position="none")
p
但是我写的方式是更常见的R格式。使用
show.legend=FALSE
在geom\u point
中。下面是使用ggplot2的钻石数据集的示例
s <- diamonds
p <- ggplot(data = s, aes(x = depth, y = price))
p + geom_point(aes(colour = factor(cut)), show.legend = FALSE)
s在geom_点内使用show.legend=FALSE
。下面是使用ggplot2的钻石数据集的示例
s <- diamonds
p <- ggplot(data = s, aes(x = depth, y = price))
p + geom_point(aes(colour = factor(cut)), show.legend = FALSE)
s试试这个:
p + geom_point(aes(colour = factor(clustering)),show.legend=FALSE)
试试这个:
p + geom_point(aes(colour = factor(clustering)),show.legend=FALSE)
上面写着:警告:忽略未知美学:秀。传奇是的,没错。图例是一个几何点参数。请检查show.legend参数前右括号的正确数目。它显示:警告:忽略未知美学:show.legendYes,是的。图例是一个几何点参数。请检查show.legend参数前右括号的正确数目。它表示:警告:忽略未知美学:show.legend它表示:警告:忽略未知美学:show.legend