[Solved] Line graph with ggplot2 in R Studio [closed]


Next time please include the head this can be done using

head(Store_sales)

  ProductID      category sales                  product
1       101        Bakery  9468              White bread
2       102 Personal Care  9390 Everday Female deodorant
3       103        Cereal  9372                 Weetabix
4       104       Produce  9276                    Apple
5       105          Meat  9268          Chicken Breasts
6       106        Bakery  9252                Pankcakes

I reproduced relevant fields to help you out. First thing is to filter out Baker items from categories.

> install.packages("tidyverse")
> library(tidyverse)

Store sales before filter

> Store_sales
  ProductID      category sales                  product
1       101        Bakery  9468              White bread
2       102 Personal Care  9390 Everday Female deodorant
3       103        Cereal  9372                 Weetabix
4       104       Produce  9276                    Apple
5       105          Meat  9268          Chicken Breasts
6       106        Bakery  9252                Pankcakes
7       107       Produce  9228                   Carrot

Filter out “Bakery” from category column into Store_sales_bakery

> Store_sales_bakery <- filter(Store_sales, category == "Bakery")

What Store_sales_bakery includes

> Store_sales_bakery
  ProductID category sales     product
1       101   Bakery  9468 White bread
2       106   Bakery  9252   Pankcakes

Unfortunately because the picture you gave us does not contain enough information to produce a line graph (you only have 1 data point for each variable which is not enough to create a line) so in its stead I created a point plot for you.

ggplot(Store_sales, aes(x = product, y = sales)) + geom_point()

ggplot point

Here is a bar plot with two variables

ggplot(Store_sales, aes(x = product, y = sales)) + geom_bar(stat = "identity")

bar plot

If you had enough data to make a line graph you would replace geom_bar() or geom_point() with geom_line()

Here is a link to ggplot cheatsheet that may help you in the future

https://www.rstudio.com/wp-content/uploads/2015/03/ggplot2-cheatsheet.pdf

0

solved Line graph with ggplot2 in R Studio [closed]