0

The y axis is not in order, I have made three separate data frames and put them into one ggpllot graph. All of the code is as follows for the graph.

library("dplyr")
library("stringr")
library("tidyverse")
library("ggplot2")

spotiify_origional <- read.csv("https://raw.githubusercontent.com/info201a-au2022/project-group-1-section-aa/main/data/charts.csv")
View(spotiify_origional)

spotify_modify <- spotiify_origional %>% 
  select(name, country, date, position, streams, artists, genres = artist_genres)

spotify_2022 <- spotify_modify %>% 
  filter(date >= "2022-01-01") %>% 
  arrange(date) %>% 
  group_by(date)

spotify_2022_global <- spotify_modify %>% 
  filter(date >= "2022-09-17") %>%
  filter(date <= "2022-09-29") %>% 
  filter(country == "global") %>% 
  filter(name == "Blank Space") %>% 
  arrange(date) %>% 
  group_by(streams)

spotify_2022_global1 <- spotify_modify %>% 
  filter(date >= "2022-09-17") %>%
  filter(date <= "2022-09-29") %>% 
  filter(country == "global") %>% 
  filter(name == "Don't Start Now") %>% 
  arrange(date) %>% 
  group_by(streams)

spotify_2022_global2 <- spotify_modify %>% 
  filter(date >= "2022-09-17") %>%
  filter(date <= "2022-09-29") %>% 
  filter(country == "global") %>% 
  filter(name == "Levitating (feat. DaBaby)") %>% 
  arrange(date) %>% 
  group_by(streams)

View(spotify_2022_global2) 

ggplot() +
  geom_line(data=spotify_2022_global, aes(x=date, y=streams, group=1), color="red") +
  geom_line(data=spotify_2022_global1, aes(x=date, y=streams, group=2), color="blue") + 
  geom_line(data=spotify_2022_global2, aes(x=date, y=streams, group=3)) + 
    geom_point()


I have tried slim and reorder functions, maybe I haven't gotten them correct. Thank you so much for helping!

zephryl
  • 14,633
  • 3
  • 11
  • 30
  • Check your data types. It looks like your `date` is still as text and perhaps your `streams` is too, since you note your y axis is out of order. As text (ie alphabetically), `9` is "higher" than `10`. I suggest before this code you use `spotify_modify <- spotify_modify %>% mutate(streams = as.numeric(streams))` or do something similar when you create `spotify_modify`. – Jon Spring Dec 02 '22 at 04:33
  • Does this answer your question? https://stackoverflow.com/questions/12774210/how-do-you-specifically-order-ggplot2-x-axis-instead-of-alphabetical-order – Jon Spring Dec 02 '22 at 04:51

0 Answers0