开始使用免费开始使用

为图形添加大小与颜色

在上一个练习中,您已经创建了一个散点图,用来展示各国的人口、预期寿命和洲别。现在,您将通过调整点的大小来传达更多信息。

本练习是课程的一部分

Tidyverse 入门

查看课程

练习说明

  • 修改散点图,使点的大小表示各国的人均 GDP(gdpPercap)。

交互式实操练习

通过完成这段示例代码来试试这个练习。

library(gapminder)
library(dplyr)
library(ggplot2)

gapminder_1952 <- gapminder %>%
  filter(year == 1952)

# Add the size aesthetic to represent a country's gdpPercap
ggplot(gapminder_1952, aes(x = pop, y = lifeExp, color = continent)) +
  geom_point() +
  scale_x_log10()
编辑并运行代码