如何在ggplot2图例中编辑比例

时间:2021-01-22 03:21:12

标签: r ggplot2

我正在处理 Arrays.copyOfRange(args, 2, args.length) 数据集。我想改变人口图例的比例,而不是科学记数法,每个数字都乘以 0.00001。有什么建议吗?

gapminder

2 个答案:

答案 0 :(得分:0)

您可以使用labels = scales::unit_format()

ggplot(gapminder1) +
  geom_point(aes(lifeExp, gdpPercap, size = pop, color = continent)) +
  facet_wrap(~ year, nrow = 1) +
  scale_y_continuous(trans = "sqrt") +
  scale_size_continuous(labels = scales::unit_format(unit = "", scale = .00001)) +
  labs(title = "Plot to recreate",
       size = "Population (100k)",
       color = "Cotinent") +
  xlab("Life Expectancy") +
  ylab("GDP per Capita") +
  guides(size = guide_legend(order = 1)) +
  theme_bw()

enter image description here

如果你不喜欢这个空间,有一个 sep = 论点。

答案 1 :(得分:0)

您可以使用:

library(ggplot2)
library(gapminder)
options(scipen = 99)

gapminder1 <- gapminder %>% 
  filter(country != "Kuwait")


ggplot(gapminder1) +
  geom_point(aes(lifeExp, gdpPercap, size = pop*.00001, color = continent)) +
  facet_wrap(~ year, nrow = 1) +
  scale_y_continuous(trans = "sqrt") +
  labs(title = "Plot to recreate",
       size = "Population (100k)",
       color = "Cotinent") +
  xlab("Life Expectancy") +
  ylab("GDP per Capita") +
  guides(size = guide_legend(order = 1)) +
  theme_bw()

enter image description here