小编hgm*_*mnz的帖子

按ggplot2图表中的因子计算

给出以下ggplot2图表:

ggplot(my_data, aes(colour=my_factor) +   
                geom_point(aes(x=prior, y=current)) +   
                facet_grid(gender ~ age)
Run Code Online (Sandbox Code Playgroud)

我想使点的大小与该先前/当前组合的my_factor的计数成比例.

ggplot(my_data, aes(colour=my_factor, 
                size=<something-here>(my_factor)) +   
                geom_point(aes(x=prior, y=current)) + 
                facet_grid(gender ~ age)
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

==编辑==

这是一个基于mpg数据集的非常简单的例子.让我们将"great_hwy"定义为hwy> 35,将"great_cty"定义为cty> 25:

mpg$great_hwy[mpg$hwy > 35]  <-1
mpg$great_hwy[mpg$hwy <= 35] <-0
mpg$great_hwy <- factor(mpg$great_hwy)

mpg$great_cty[mpg$cty > 25]  <- 1
mpg$great_cty[mpg$cty <= 25] <- 0
mpg$great_cty <- factor(mpg$great_cty)
Run Code Online (Sandbox Code Playgroud)

如果我们对great_hwy和great_cty进行策划,它就不会告诉我们太多:

ggplot(mpg) + geom_point(aes(x=great_cty, y=great_hwy))
Run Code Online (Sandbox Code Playgroud)

如何根据x/y点的数量使数据点更大?希望这清除它,但请让我知道.

r ggplot2

8
推荐指数
1
解决办法
6040
查看次数

标签 统计

ggplot2 ×1

r ×1