我使用的数据是:
x y size
589 127 16,4724409449
465 58 21,0517241379
408 58 15,9137931034
我用它来制作气泡图
library(ggplot2)
a <- read.csv("numbers.csv", header = TRUE)
ggplot(a,aes(x,y))+geom_point(size=a$size)
但在图表中我看不到任何泡沫。我该怎么做?
以下是数据框的输入:
structure(list(x = c(589L, 465L, 408L), y = c(127L, 58L, 58L),
size = structure(c(2L, 3L, 1L), .Label = c("15,9137931034",
"16,4724409449", "21,0517241379"), class = "factor")), .Names = c("x",
"y", "size"), class = "data.frame", row.names = c(NA, -3L))
此外,如果可以为每个气泡添加名称和不同的颜色吗?
x y size name
589 127 16,4724409449 nameA
465 58 21,0517241379 nameB
408 58 15,9137931034 nameC
答案 0 :(得分:0)
要生成尺寸映射到a$size
,颜色和标签为a$name
的气泡图,我们可以尝试:
ggplot(a, aes(x, y, label = name)) +
geom_point(aes(size = size, colour = name)) +
geom_text()