開始使用免費開始

將 x 軸設為對數刻度

你先前已建立一個散佈圖,x 軸是人口數,y 軸是平均壽命。由於人口數跨越好幾個數量級,而且有些國家的人口遠高於其他國家,把 x 軸改為對數刻度會更合適。

本練習屬於課程

Tidyverse 入門

檢視課程

練習說明

  • 將現有的散佈圖(已提供程式碼)改成把 x 軸(代表人口數)設為對數刻度。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

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

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

# Change this plot to put the x-axis on a log scale
ggplot(gapminder_1952, aes(x = pop, y = lifeExp)) +
  geom_point()
編輯並執行程式碼