气泡图
如何画气泡图?
载入R包。
library(ggplot2)
set.seed(112)
mydata <- data.frame(x = 1:15,
y = x + rnorm(15),
z = c(1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5),
g = rep(c("A", "B", "C"), 5)
)
mydata
ggplot(mydata, aes(x, y, fill = g, size = z)) +
geom_point(alpha = 0.5, shape = 21)
ggplot(mydata, aes(x, y, fill = g, size = z)) +
geom_point(alpha = 0.5, shape = 21, stroke = 1) +
scale_fill_brewer(type = "qual", palette = 2) +
scale_size_continuous(range = c(3, 10)) +
theme_classic()
2023-02-21 17:37