我想用 scatterpie 制作 6 个不同的馅饼。馅饼有 101 个不同的类别(并非所有馅饼都有 101 个),所以我希望能够区分颜色。
这并没有给我足够的颜色(我可以通过看馅饼来判断)
ggplot(wholebody_cutLH_wide_t) +
# annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
geom_scatterpie(aes(x=imX, y=imY,r=radius),
data=wholebody_cutLH_wide_t, cols=colnames(wholebody_cutLH_wide_t[1:101]),color=NA) +
#scale_color_manual(values=sample(allcolors,101)) +
scale_x_continuous(expand=c(0,0), lim=c(0,3)) +
scale_y_continuous(expand=c(0,0), lim=c(0,6)) +
theme(legend.position="none",
panel.background = element_rect(fill = "transparent") # bg of the panel
, plot.background = element_rect(fill = "transparent") # bg of the plot
, panel.grid.major = element_blank() # get rid of major grid
, panel.grid.minor = element_blank(), # get rid of minor grid
line = element_blank(),
text = element_blank(),
title = element_blank()
)
然后,如果我尝试如下手动设置颜色,我会得到一个空白屏幕。如果我尝试在 scatterpie (color=sample(allcolors,101)) 中设置颜色,则会收到错误消息
错误:美学长度必须为 1 或与数据 (2864) 相同:颜色
allcolors = grDevices::colors()[grep('gr(a|e)y', grDevices::colors(), invert = T)]
ggplot(wholebody_cutLH_wide_t) +
# annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
geom_scatterpie(aes(x=imX, y=imY,r=radius),
data=wholebody_cutLH_wide_t, cols=colnames(wholebody_cutLH_wide_t[1:101]),color=NA) +
scale_color_manual(values=sample(allcolors,101)) +
scale_x_continuous(expand=c(0,0), lim=c(0,3)) +
scale_y_continuous(expand=c(0,0), lim=c(0,6)) +
theme(legend.position="none",
panel.background = element_rect(fill = "transparent") # bg of the panel
, plot.background = element_rect(fill = "transparent") # bg of the plot
, panel.grid.major = element_blank() # get rid of major grid
, panel.grid.minor = element_blank(), # get rid of minor grid
line = element_blank(),
text = element_blank(),
title = element_blank()
)