可能有一个简单的解决方案,但是我是个新手,不知道它是什么-因此,我将不胜感激任何帮助。
我正在尝试创建一个图表,该图表将显示首次响应的平均时间与响应速度。但是,我希望每个点的大小都代表实际大小(下表中的活动用户数),而不是相对大小。
数据框表:
ggplot(benchmarksdf, aes(benchmarksdf$`Avg. Time To First Response`,benchmarksdf$`Response Rate`)) +
geom_point(shape=21, aes(fill=benchmarksdf$`Community Name`, size=benchmarksdf$`Active Users`)) +
geom_text(aes(label=benchmarksdf$`Community Name`), check_overlap = T, show.legend = F, size = 3, vjust = 2) +
labs(title = "Benchmarking Top Enterprise Communities",
subtitle = "Comparing top brand communities by response rate and avg. time to first response",
y = "Response Rate %",
x = "Avg. time to first response (days)") + scale_x_reverse () +
theme_classic()+
theme(legend.position = 'none',aspect.ratio = 0.8)
这导致以下结果:
按大小划分的社区总图:
我的眼睛可能在欺骗我,但此刻似乎每个点的大小都是通过相对性而不是数据值来确定的。
有没有办法纠正这个问题,并使其代表绝对活跃用户数?
答案 0 :(得分:0)
检查Active users
是numerics
而不是factors
。
我尝试使用数据包midwest
中的数据集ggplot2
,显示似乎正确:
library(ggplot2)
data(midwest)
gg <- ggplot(midwest[1:10,],aes(x = area, y = poptotal)) +
geom_point(aes(size=popdensity)) +
labs(title = "Area vs Pop", subtitle = "Midwest dataset", y = "Pop", x = "Area") +
geom_text(aes(label=county),size = 3,hjust = 0.5, vjust = -1.5)
gg
答案 1 :(得分:0)
您将不得不将大小比例更改为连续大小,而不是默认大小。 尝试以下代码:
ggplot(benchmarksdf, aes(x =benchmarksdf$Avg.time.to.first.response,y= benchmarksdf$Response.rate)) + geom_point(shape=21, aes(fill=benchmarksdf$Community.name, size = benchmarksdf$Active.users)) +scale_size_continuous(limits = c(0,2100))+geom_text(aes(label=benchmarksdf$Community.name), check_overlap = T, show.legend = F, size = 3, vjust = 2) +
labs(title = "Benchmarking Top Enterprise Communities",
subtitle = "Comparing top brand communities by response rate and avg. time to first response",
y = "Response Rate %",
x = "Avg. time to first response (days)") + scale_x_reverse () +
theme_classic()+
theme(legend.position = 'none',aspect.ratio = 0.8)