【发布时间】:2019-09-18 19:15:50
【问题描述】:
我使用 RStudio 中的 gapminder 包中的数据在 ggplot2 中创建了一个图表。我很好奇如何将水平轴转换为对数刻度。我确实使用了函数 scale_x_continuous 但在运行代码后图形消失了。
ggplot(data = gapminder07) + geom_point(mapping = aes(x = gdpPercap, y = lifeExp))
p <- ggplot(gapminder07, aes(x = gdpPercap, y=lifeExp, label = country))
p + geom_text()
p + scale_x_continuous(trans = 'log10')
编辑* 添加拟合线时会出现同样的问题。线出现,但数据点消失。
ggplot(data = gapminder07) + geom_point(mapping = aes(x = gdpPercap, y = lifeExp))
p <- ggplot(gapminder07, aes(x = gdpPercap, y=lifeExp, label = country))
p + geom_text()
p + geom_smooth()
【问题讨论】: