r - 点大小表示值时如何更改点大小的范围
问题描述
我想保留 ggplot2 散点图中点之间的相对大小差异,但增加所有点的大小,使它们更明显。
这是代码。唯一相关的一点是点大小与变量相关,所以我不想手动调整它。
ggplot(WSC5, aes(x = DCount, y = meandays, color = Department, size = NumCats)) +
geom_point() +
theme_minimal() +
labs(y = "Mean Number of Days Open Per Case",
x = "Number of Cases",
title = "Cases",
size = "Number of Categories") +
theme(plot.title = element_text(hjust = .5)) +
guides(color = guide_legend(override.aes = list(size =5)))
上面的代码生成了一个可行的图表,但这些点太小而无法在幻灯片演示中看到。我想要更大的分数。
解决方案
欢迎来到stackoverflow。我想你可以得到你需要的scale_size()
df <-
diamonds %>%
filter(clarity == "I1") %>%
mutate(
depth = floor(depth),
price = round(price, -3)
) %>%
count(depth, price)
no_scale <-
ggplot(df, aes(depth, price, size = n)) +
geom_point(alpha = 0.3) +
coord_fixed(ratio = 1/1000)
with_scale <-
ggplot(df, aes(depth, price, size = n)) +
geom_point(alpha = 0.3) +
scale_size(
breaks = c(1, 10, 25, 50),
range = c(2, 6)
) +
coord_fixed(ratio = 1/1000)
gridExtra::grid.arrange(no_scale, with_scale, nrow = 1)
为了在这个网站上获得好的结果,总是提供一些代码来创建一个小数据集,这样我们就可以自己运行它。本文提供了有关如何执行此操作的详细信息:
https://reprex.tidyverse.org/articles/articles/datapasta-reprex.html
推荐阅读
- php - Laravel 模型 IDE 助手和枚举类型
- formal-languages - 如何使用运算符获取 TLA+/PlusCal 中序列元素的总和?
- mysql - (初学者)SQL查询无缘无故抛出错误
- python - Linux系统资料 c++ vs bash vs python
- angular - 如何在单击时显示和隐藏单个项目的详细信息
- oracle - 无法正确创建程序。在 Oracle 中遇到符号“文件结尾”
- powershell - 尝试使用 powershell 以管理员身份在本地运行脚本块
- python - 元组到字典的Python元组
- docker - 错误:`sass-loader` 需要 `node-sass` >=4。在 Docker 容器内
- database - 我想打印最少的道路数据