我正在尝试在图像顶部绘制多个饼图。我想用来custom_annotation
绘制光栅图像。但现在我什至无法获得多个饼图。
最终,我希望在图像顶部的不同点绘制 6 个饼图。imX
并imY
给出饼图应该在图像上的坐标。
head(wholebody_cutLH_wide_t[c(1,2,102,103,104)])
Acidobacteriaceae Actinomycetaceae imX imY radius
1 0.000000e+00 7.665687e-05 2.00 5.5 0.5
2 0.000000e+00 4.580237e-04 1.50 1.0 0.5
3 0.000000e+00 4.112573e-04 1.75 2.0 0.5
4 6.431473e-04 3.856008e-02 0.30 1.0 0.5
5 0.000000e+00 3.013013e-04 1.50 4.8 0.5
6 3.399756e-05 1.372986e-02 1.50 5.2 0.5
现在这是我的尝试scatterpie
:
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=NA,color=sample(allcolors,101)) +
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()
)
现在我的错误是:
Error: Only strings can be converted to symbols
dplyr
这是我对and的尝试ggforce
:
dat_pies<-left_join(wholebody_cutLH,
wholebody_cutLH %>%
group_by(tax_rank) %>%
summarize(Cnt_total = sum(count_norm))) %>%
group_by(tax_rank) %>%
mutate(end_angle = 2*pi*cumsum(count_norm)/Cnt_total, # ending angle for each pie slice
start_angle = lag(end_angle, default = 0), # starting angle for each pie slice
mid_angle = 0.5*(start_angle + end_angle))
ggplot(dat_pies) +
geom_arc_bar(aes(x0 = imX, y0 = imY, r0 = 0, r = rpie,
start = start_angle, end = end_angle, fill = Volume)) +
geom_text(aes(x = rlabel*sin(mid_angle), y = rlabel*cos(mid_angle), label = Cnt),
hjust = 0.5, vjust = 0.5) +
coord_fixed() +
scale_x_continuous(expand=c(0,0), lim=c(0,3)) +
scale_y_continuous(expand=c(0,0), lim=c(0,6)) +
这里我的错误是:
Error in ggplot(dat_pies) + geom_arc_bar(aes(x0 = imX, y0 = imY, r0 = 0, :
could not find function "+<-"
对这两种方法的任何帮助都会很棒。谢谢