我承认这个问题至少已被问过两次,但所提供的答案都不适合我。
我的数据与ggbiplot wine
示例非常相似,所以我只是用它来说明我的问题。
我希望我的数据点具有不同的颜色和形状,因此它们在以彩色打印时看起来很漂亮,但在用黑白打印时仍然可以识别。这实际上运作得很好,但传说并没有发挥作用。
require(scales)
library(devtools)
install_github("vqv/ggbiplot")
library(ggbiplot)
data(wine)
wine.pca <- prcomp(wine, scale. = TRUE)
ggbiplot(wine.pca, obs.scale = 1, var.scale = 1,
groups = wine.class, ellipse = TRUE, circle = TRUE, var.axes=FALSE) +
scale_color_discrete(name = '') +
geom_point(aes(colour=wine.class,shape=wine.class),size=2) +
theme(legend.direction = 'horizontal', legend.position = 'top')
传说显然不是我想要的。形状和颜色应该在同一个图例中。
(作为奖励,我也想从积分中删除小行,但如果这不容易实现,我可以和他们一起生活。)
第一个建议
data(wine)
wine.pca <- prcomp(wine, scale. = TRUE)
ggbiplot(wine.pca, obs.scale = 1, var.scale = 1,
groups = wine.class, ellipse = TRUE, circle = TRUE, var.axes=FALSE) +
scale_color_discrete(name = '') +
geom_point(aes(colour = wine.class), size = "2") +
scale_color_manual(values=c(16,17,18)) +
theme(legend.direction = 'horizontal', legend.position = 'top')
产生此错误消息(根本没有绘图)
Scale for 'colour' is already present. Adding another scale for 'colour',
which will replace the existing scale.
Fehler in coords$size * .pt :
nicht-numerisches Argument für binären Operator
(最后两行转换为&#34; coords中的错误$ size * .pt:二元运算符的非数字参数)
第二个建议
data(wine)
wine.pca <- prcomp(wine, scale. = TRUE)
ggbiplot(wine.pca, obs.scale = 1, var.scale = 1,
groups = wine.class, ellipse = TRUE, circle = TRUE, var.axes=FALSE) +
scale_color_discrete(name = '') +
geom_point(size = 2) +
scale_colour_manual(name = "Wines",
labels = c("barolo","grignolino","barbera"),
values = c("blue", "red", "green")) +
scale_shape_manual(name = "Wines",
labels = c("barolo","grignolino","barbera"),
values = c(17,18,19))
给我这个错误消息
Scale for 'colour' is already present. Adding another scale for 'colour',
which will replace the existing scale.
带有彩色椭圆的有趣情节,带有彩色点的图例,但黑色数据点。
我担心我对R绘图的了解不足以做出任何相关的事情。有人能以正确的方式指出我吗?