1

I have a work project where I've been given a spreadsheet with tons of data and I want to plot it using R to look for trends.

The issue I am having is that I cannot plot it correctly using ggplot because I want to place to variables in the Y-Axis.

My goal is to plot "interest" and "awareness" on the Y-axis in different colors, say green and blue, and "admissions" on the X-axis.

Unfortunately, I am new StackOverflow and cannot include my Excel spreadsheet, so I included a screenshot for reference.

Excel note - the actual spreadsheet has 381 titles

ggplot(data =data, aes(x = 'admissions', y = 
'interest')) +  geom_line()
stefan
  • 90,330
  • 6
  • 25
  • 51
Hi2736464
  • 47
  • 7
  • Please do not post an image of code/data/errors [for these reasons](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557). Please just include the code, console output, or data using e.g. `dput(head(NAME_OF_DATASET))` directly. Also see how to make [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – stefan Apr 06 '22 at 20:26
  • ... this said: To plot multiple columns you could do so via brute force, i.e. via multiple `geom_line` or as the preferred approach by converting your data to long format using e.g. `tidyr::pivot_longer()`. One more point: Remove the quotes around your column names, just do e.g. `x = admissions`. – stefan Apr 06 '22 at 20:30

1 Answers1

3

Here is one way we could do it:

library(tidyverse)

df %>% 
  pivot_longer(
    c(interest, awarenes)
  ) %>% 
  mutate(value_number = parse_number(value)) %>% 
  ggplot(aes(x = admission, y = value_number, color= name, group=name)) +
  geom_point()+
  geom_line()+ 
  scale_y_continuous(labels = function(x) paste0(x, "%"))+
  scale_color_manual(values=c("green", "blue"))+
  theme_bw()

enter image description here

TarJae
  • 72,363
  • 6
  • 19
  • 66