0

Ciao guys,

I have the following 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"))

My goal is to display the variable task on my x axis as well. I don't know if it would be necessary to generate a second x axis. I know that the question is pretty straightforward and was definitely asked before but I fail as I only found solutions for barplots.

This is my plot. Note also, that I use in my real data geom_smooth rather than geom_line. But I guess this should be irrespective when creating a second x axis.

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)"))

Many thanks in advance

Freddy

freddywit
  • 301
  • 1
  • 5
  • 1
    Have you tried to use `ggplot2::sec_axis`? It's the canonical (only?) way to get a second axis. – r2evans May 15 '21 at 22:19
  • I'm having a hard time imagining this would be a plot that was easy to understand. Almost all requests for a second axis involve a second y-variable rather than a second x-axis. – IRTFM May 15 '21 at 22:25
  • After looking at the nominees for duplicate, and reviewing your question, I'm thinking that what you really wanted was a second set of axis labels, rather than a second axis. – IRTFM May 15 '21 at 23:46

0 Answers0