磅值表示值时如何改变磅值范围
How to change the range of point sizes when point size represents values
我想保留 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)))
以上代码生成了一个可行的图表,但这些点太小而无法在幻灯片演示中看到。我想要更大的积分。
欢迎使用 Whosebug。我想你可以用 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
我想保留 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)))
以上代码生成了一个可行的图表,但这些点太小而无法在幻灯片演示中看到。我想要更大的积分。
欢迎使用 Whosebug。我想你可以用 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