How to plot x- and y-axis lines on ggplot?

I am trying to plot axis lines on my gpplot, but I keep getting an error. Would anyone know how to troubleshoot to:

  • Plot x-axis line
  • Plot y-axis line
# plot4 (regression coefficients)
p4 <- ggplot(df3, aes(x=reorder(topics,v1970), y=lm_coef)) + 
  geom_bar(stat='identity', aes(fill = cat))  + 
  labs(y = "\nYear Coefficients") +
  theme(axis.title.y = element_blank(),
        axis.text.y = element_blank(),
        panel.background = element_rect(fill = NA),
        axis.ticks.length.y = unit(.25, "cm"), # make ticks point outwards on y-axis
        axis.ticks.length.x = unit(.25, "cm"), # make ticks point outwards on x-axis
        axis.text.x = element_text(margin = margin(t = .3, unit = "cm") 
        )) +
        #axis.line.x = element_line(linewidth = 0.1, colour = "black")

What is the error?
Are you saying that you are getting error messages or the plot is not exactly what you want?

Can you describe the problem in more detail, post any erro or warning messages and supply some sample data? We may net to also see more of your code .

A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where mydata is your data. Copy the output and paste it here.

Some general information on posting to the forum: FAQ

1 Like

Thanks. I don't know why, but when I tried running the line of code that wasn't working before, it worked (the hashed out code above):

axis.line.x = element_line(linewidth = 0.1, colour = "black")

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.