how to add second layer of X axis

I want to add a second later of x-axis in gglpot. Just like that....
june,july, aug, sep= SWM
Oct, Nov= PM
Dec, Jan, Feb= NEM
March, april, may=PrM

A demo is given in the picture....just seeWhatsApp Image 2020-05-03 at 4.38.18 PM

There are a couple approaches to this described in these Stack Overflow answers (essentially, with or without faceting):


I saw the coding. But the above are about bar chart. In case of line chart, it shows wrong

My code is
library(readr)
data <- read_csv("data.csv")
data$Month <- factor(data$Month, levels = data$Month)
library(ggplot2)

ggplot(data, aes(x = Month, y = POC, group = Seasons)) + geom_line() + geom_point() +
geom_errorbar(aes(ymax = sd_max, ymin = sd_min), width = 0.25) +
coord_cartesian(ylim = c(0.95 * min(data$sd_min), 1.05 * max(data$sd_max)),
expand = FALSE, clip = "off") + theme_classic()+
theme(axis.text.x = element_text(angle = 90, hjust = 1))

What code is essential to add the ggplot to show the second layer just like the attached

image.
please, help

In that case you're going to want to use annotation.

I haven't done this with a line chart before, but I'd recommend taking a look at the cowplot package, which gives you very fine-grained control over annotations for plots (including ggplot2-generated ones)

Hopefully someone else is more familiar with the process. Good luck.

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