小编dav*_*ave的帖子

使用 ggplot 与使用基本 R 函数时的图形结果不同?

我正在为 R 中的一个项目创建一些简单的图表。使用 ggplot2 包时,我得到了意想不到的结果,因此我默认回到基本 R。在基本 R 中重新创建绘图时,我得到了正确的结果。现在我只是想知道为什么会产生不同的结果?

\n

最初,这是使用 ggplot 的代码和结果(这是不正确的):

\n
ggplot(KBUF, aes(x = TEMP, y = HGHT)) +\ngeom_line(aes(color = "Temperature"), size = 1) +\ngeom_line(aes(x = DEWP, color = "Dew Point"), size = 1) +\nscale_color_manual(values = c("blue", "red")) +\nlabs(x = "Temperature (\xc2\xb0C)", y = "Height")\n
Run Code Online (Sandbox Code Playgroud)\n

这是输出图

\n

我在 R 基础上绘制的正确图

\n

\n

有以下代码:

\n
plot(KNKX$TEMP, KNKX$HGHT, type = "l", col = "blue", xlab = "Temperature (\xc2\xb0C)", ylab = "Height")\n\nlines(KNKX$DEWP, KNKX$HGHT, col = "red")\n\nlegend("topright", legend = c("Temperature", "Dew Point"), …
Run Code Online (Sandbox Code Playgroud)

graphing plot r data-analysis ggplot2

2
推荐指数
1
解决办法
60
查看次数

标签 统计

data-analysis ×1

ggplot2 ×1

graphing ×1

plot ×1

r ×1