0

In ggplot2, I am trying to make the axes have green lines.

textMessagesLine + 
  stat_summary(fun = mean, geom = "point", aes(group = Group, color = Group, shape = Group)) + 
  stat_summary(fun = mean, geom = "line", aes(group = Group, linetype = Group, color = Group)) + 
  stat_summary(fun.data = mean_cl_boot, geom = "errorbar", width = 0.05, aes(color = Group)) + 
  scale_y_continuous(limits = c(0,100)) +
  labs(x = "Time", y = "Mean Grammar Score", color = "Group") + 
  theme_classic() + 
  theme(panel.grid.major = element_line(color = "Blue", linewidth = 0.1), panel.grid.minor = element_line(color = "Red", linewidth = 0.1)) +
  theme(axis.line = theme_segment(color = "Green"))

I am getting Error in element_segment(color = "Green") : could not find function "element_segment"

I tried using theme(axis.line = element_segment(color = "Green")) instead of theme(axis.line = theme_segment(color = "Green")) but to no avail.

[Here, it's recommended to use theme_segment()][1] [1]: https://stackoverflow.com/questions/10861773/remove-grid-background-color-and-top-and-right-borders-from-ggplot2

but this post uses opts() which is replaced by theme() but doesn't accept theme_segment() (or theme_line()).

In my original code I had used theme_line(), but after looking it up, I used element_line() here theme(panel.grid.major = element_line(color = "Blue", linewidth = 0.1), panel.grid.minor = element_line(color = "Red", linewidth = 0.1)), which worked.

Do you have any suggestions as to how to use the segment option?

  • 1
    Try with `element_line`. The post you referenced is pretty old and the answer which uses `theme_segment`, `theme_blank`, ... will no longer work with more recent versions of ggplot2. In general you could have a look at `?theme` to lookup the type of `element_xxx` you have to pass to a theme element, e.g. for `axis.line` this is `element_line`. – stefan May 30 '23 at 16:20
  • 1
    @stefan, thanks for your replying! You're right, I should have looked up `?theme`. I am studying from a textbook from 2018. It seems that `element_segment` or `theme_segment` doesn't exist anymore. – WizardOfOzi May 30 '23 at 16:31

0 Answers0