首页 > 解决方案 > 在绘图上创建第二个 xaxis

问题描述

小伙子们,

我有以下dataframe

obj <- data.frame (percentile = c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6 , 0.7, 0.8, 0.9, 1),
                   emp_change = c(0.05, 0.04, 0.03, 0.05, 0.06, 0.04, 0.02, 0.09, 0.08, 0.06), 
                   task = c("Manual", "Manual", "Manual", "Routine-Manual", "Routine-Manual",
                            "Routine-Abstract", "Routine-Abstract", "Abstract", "Abstract", "Abstract"))

task我的目标也是在我的 x 轴上显示变量。我不知道是否有必要生成第二个 x 轴。我知道这个问题很简单,之前肯定有人问过,但我失败了,因为我只找到了条形图的解决方案。

这是我的阴谋。另请注意,我在真实数据中使用 geom_smooth 而不是 geom_line。但我想这在创建第二个 x 轴时应该无关紧要。

plot <- ggplot() +
  geom_line(data = obj, aes(x= percentile, y= emp_change, group = 1, color="observed", linetype = "observed"), 
      size=1.5, linetype = "dotdash")
print(plot +  theme(axis.text.x=element_text(angle = 60, hjust = 1)) + 
        theme(axis.title=element_text(size=12)) +
        labs(y="100 x Change in Employment Share", x = "Percentile ranked by task input and log of mean occupational wage (1990)"))

提前谢谢了

弗雷迪

标签: r

解决方案


推荐阅读