我可以忽略其中一个变量的颜色值吗? (即:我希望变量C像原样那样按比例绘制大小,但是忽略按值着色并具有独立的颜色(黑色))
data <- tibble::tibble(
value = c(4.07, 5.76, 2.87,4.94,5.48, 6.75,1.53,1.35, 1.32),
Variable = rep(c(rep("A",3),rep("B",3), rep("C",3))),
Experiment = rep(c(1:3),3))
data <- data %>%group_by(Variable)%>%
mutate(scaled_val = scale(value)) %>%
ungroup()
data$Variable <- factor(data$Variable,levels=rev(unique(data$Variable)))
ggplot(data, aes(x = Experiment, y = Variable, label=NA)) +
geom_point(aes(size = scaled_val, colour = value)) +
geom_text(hjust = 1, size = 2) +
theme_bw()+
scale_color_gradient(low = "lightblue", high = "darkblue")+
scale_x_discrete(expand=c(1,0))+
coord_fixed(ratio=4)
答案 0 :(得分:2)
如果我的理解正确,您应该能够将数据geom_point
中的子集并覆盖两个geom_point
几何:
ggplot(data, aes(x = Experiment, y = Variable, label=NA)) +
geom_point(data=subset(data, Variable %in% c("A","B")), aes(size = scaled_val, colour = value)) +
geom_point(data=subset(data, Variable=="C"), aes(size = scaled_val)) +
geom_text(hjust = 1, size = 2) +
theme_bw()+
scale_color_gradient(low = "lightblue", high = "darkblue")+
scale_x_discrete(expand=c(1,0))+
coord_fixed(ratio=4)