converting character column to date

Hi guys
Here is my code:

data <- read_csv("texasempl.csv")

df <- data %>%
pivot_longer(cols = ! Periode,
names_to = "region",
values_to = "value") %>%
mutate(region = as.factor(region))

Problem 1: Could you guys help me to convert a character string such as 2013 - Q1, 2013 - Q2, 2013 - Q3....2018-Q1 to date.

the data looks like this:

Gold Silver
Oct-07 754.60 13.7217
Nov-07 806.25 14.6720
Dec-07 803.20 14.3124
Jan-08 889.60 16.0591
Feb-08 922.30 17.6663
Mar-08 968.43 19.2160
Apr-08 909.71 17.5107
May-08 888.66 17.0491
Jun-08 889.49 17.0395
Jul-08 939.77 18.0641

Problem 2: I could make a graph using that column as x-axis. How could i just show year on x-axis and Q1 separately into two lines

ggplot() +
geom_line(data= df ,
aes(x= Periode, y = value, group = region, color = region), size= 1.5) +

#scale_x_continuous(breaks=seq(1982, 2007, by = 5))+

scale_y_continuous(breaks=seq(50,175, by = 25)) +

theme(plot.title = element_markdown(size=18, hjust =5.5, lineheight = 6),
    plot.subtitle = element_markdown(size=12, color="#777B7E"),
    axis.title.y = element_blank(),
    axis.ticks.y = element_blank(),
    axis.text.y = element_text(color ="#777B7E", size = 12),
    axis.title.x = element_blank(),
    axis.text.x = element_text(color ="#777B7E", size = 12),
    axis.line.x = element_line(color="grey", size = 1),
    axis.ticks.x = element_line(color="#a9a9a9"),
    #legend.position = "none",
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    panel.background = element_blank(),
    plot.margin = unit(c(0.5,0,0.5,0.5), "cm")) 

Thank you very much !

Trung

Next time, provide a reproducible example of your code, not a screenshot.

Q1 - see - Converting excel dates:

Q2 - perhaps provide an example?

This topic was automatically closed 21 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.