基于单独的数据帧使用geom_label_Reject时应用连续比例
根据答案中的方法大纲,我有一个绘图,它从一个单独的数据框中画出标签。然而,我想知道是否有一种方法可以使用基于单独的数据帧使用geom_label_Reject时应用连续比例,r,ggplot2,R,Ggplot2,根据答案中的方法大纲,我有一个绘图,它从一个单独的数据框中画出标签。然而,我想知道是否有一种方法可以使用geom_label_repel而不是geom_text,但对标签应用连续的色标 原来的情节是: df %>% ggplot(aes(variable, value, width =.7)) + geom_col(col="black",aes(fill=X1)) + #Black border around the bars expand_limits(y = 0) + sc
geom_label_repel
而不是geom_text
,但对标签应用连续的色标
原来的情节是:
df %>%
ggplot(aes(variable, value, width =.7)) +
geom_col(col="black",aes(fill=X1)) + #Black border around the bars
expand_limits(y = 0) +
scale_y_continuous(limits = c(0,70),
breaks=c(0,10,20, 30,40, 50,60,70),
expand = c(0.02, 0.02))+
geom_label_repel(data = df_max,
aes(label = max, y = max))+ #Here the text is added
scale_fill_brewer(palette="Dark2") + #Changes the colour scale
labs(x="Breed",
y="Weighted score",
fill="") +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.direction="vertical", legend.position=c(0.9, 0.85),
legend.text=element_text(size=11),
legend.key = element_rect(size = 4),
legend.key.size = unit(1.5, 'lines'))
我猜,如果可能的话,它将包括一个变化的scale\u fill\u gradient
,但我还没有找到一种方法让它工作
如果我包括一个比例\填充\梯度
,如下所示:
df %>%
ggplot(aes(variable, value, width =.7)) +
geom_col(col="black",aes(fill=X1)) + #Black border around the bars
expand_limits(y = 0) +
scale_fill_gradient2(data=df_max, aes(y=max),
fill=max,
low='blue', mid='green', high='red', midpoint = 10)+
scale_y_continuous(limits = c(0,70),
breaks=c(0,10,20, 30,40, 50,60, 70),
expand = c(0.02, 0.02))+
geom_label_repel(data = df_max,
aes(label = max, y = max))+ #Here the text is added
scale_fill_brewer(palette="Dark2") + #Changes the colour scale
labs(x="Breed",
y="Weighted score",
fill="") +
theme_bw() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.direction="vertical",
legend.position=c(0.9, 0.85),
legend.text=element_text(size=11),
legend.key = element_rect(size = 4),
legend.key.size = unit(1.5, 'lines')) # Ensures spacing between the
# different lines on the legend.
我得到以下错误:
一个连续的调色板(而不是深色的)能满足你的需要吗?谢谢@Jordo82,但是,如果我在那里更改颜色,它会影响主绘图,而不是创建标签的辅助数据框。它正在寻找一种方法来引用我找不到的辅助数据帧
Error in continuous_scale("fill", "gradient2", div_gradient_pal(low, mid, :
unused arguments (data = list(variable = 1:4, max = c(15, 14.7, 9.7, 4.1)),
fill = .Primitive("max"))