plotting line graph with 1 variable

Hi,

I am trying to plot line graph to show how casual and member percentages changed over time.
The data frame i am using is below.

How do i proceed?

Something along the lines of the below?

# Load libraries ----------------------------------------------------------
library("tidyverse")


# Define example data -----------------------------------------------------
my_data <- tribble(
  ~Qtr, ~causal, ~member,
  "Q1_21", 112284, 262671,
  "Q1_22", 129818, 373603,
  "Q2_21", 764198, 834260,
  "Q3_21", 1218617, 1164292,
  "Q4_21", 433909, 804835
)


# Wrangle data ------------------------------------------------------------
my_data <- my_data %>% 
  mutate(Qtr = factor(Qtr),
         Qtr_num = as.numeric(Qtr))

my_data_long <- my_data %>% 
  pivot_longer(cols = c(-Qtr, -Qtr_num),
               names_to = "variable",
               values_to = "value")


# Visualise ---------------------------------------------------------------
my_data_long %>% 
  ggplot(aes(x = Qtr_num,
             y = value,
             colour = variable)) +
  geom_line() +
  scale_x_continuous(labels = my_data$Qtr) +
  theme_bw()

?

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.