我有这个数据集
df <- data.frame(year = seq(1970, 2015, by = 5),
staff = c(219, 231, 259, 352, 448, 427, 556, 555, 602, 622),
applications = c(5820, 7107, 6135, 16119, 19381, 36611, 54962, 45759, 40358, 458582))
我想进行探索性分析,并希望根据收到的申请来比较员工人数是否在增长。我使用excel绘制了一个折线图:
这不是很有意义。 我还记录了两个几乎都得到了预期结果的变量,但我想知道带有日志的图表是否可以解释为非数学家。因为我想在演示文稿中使用这些图表给我的管理人员,他们对统计数据或数学知之甚少。 我的问题是如何处理这种情况以绘制有意义的图表。 我有一种直觉,认为R可能有更好的解决方案(这就是我在这里问的原因)而不是Excel,但问题是'如何'?
任何帮助都将受到高度赞赏。
答案 0 :(得分:3)
一项建议是将您的指标更改为某种类型的比率指标。例如,progressBar.progress
。在下文中,我将使用staff per applications
:
staff per 1,000 applications
我们可以在不使用library(ggplot2)
df <- data.frame(year = seq(1970, 2015, by = 5),
staff = c(219, 231, 259, 352, 448, 427, 556, 555, 602, 622),
applications = c(5820, 7107, 6135, 16119, 19381, 36611, 54962, 45759, 40358, 458582))
ggplot(data = df, aes(x = year, y = staff / (applications / 1000))) +
geom_point(size = 3) +
geom_line() +
ggtitle("Staff per 1,000 Applications")
的情况下获得相同的结果:
ggplot2
或者,您可以使数据集更加整洁(有关详细信息,请参阅this,this和/或this)并使用{{1}绘制两个方面} scale:
with(df,
plot(x = year, y = staff / (applications / 1000), type = "l", main = "Staff per 1,000 Applications") +
points(x = year, y = staff / (applications / 1000), pch = 21, cex = 2, bg = "black")
)
答案 1 :(得分:1)
我建议您将facet_grid
与scales = "free_y"
一起使用。
ggplot(reshape2::melt(df, 1), aes(year, value)) +
geom_line() + geom_point() +
facet_grid(variable ~ ., scales = 'free_y')
答案 2 :(得分:0)
we can use this process:
library(ggplot2)
library(reshape2)
ggplot(df, aes(year)) +
geom_line(aes(y = staff, colour = "staff")) +
geom_line(aes(y = applications, colour = "applications"))
df <- data.frame(year = seq(1970, 2015, by = 5),
staff = c(219, 231, 259, 352, 448, 427, 556, 555, 602, 622),
applications = c(5820, 7107, 6135, 16119, 19381, 36611, 54962, 45759, 40358, 458582)