-1

I have a dataset with 2 variables. One variable is the day of the week (7 possible values) and the other variable is a numeric value.

I want to make a histogram with numeric values only when they are corresponding to a Monday. I have attached a screenshot of my dataset.

Should I create a dataset only Monday's value? How could I do that?

enter image description here]1

zx8754
  • 52,746
  • 12
  • 114
  • 209
Zach
  • 29
  • 1
  • 4

2 Answers2

1

You can try to subset your dataframe directly in ggplot2 by using subset:

library(ggplot2)
ggplot(data = subset(df, Day_Week == "Monday"), aes(x = total_price_diff_from_lowest))+
   geom_histogram()

Is it what you are looking for ?

If not, please consider providing a reproducible example of your dataset by following this guide: How to make a great R reproducible example and to clarify what kind of plot you are looking for.

NB: ggplot2 is a package for making all kind of plot (see: https://ggplot2.tidyverse.org/) but it is not installed by default in R, so you will have to install it using install.packages("ggplot2"). If you are looking for a solution using base r plot, please see @RonakShah's answer.

dc37
  • 15,840
  • 4
  • 15
  • 32
1

You could subset the total_price_diff_from_lowest values where Day_week is "Monday"

hist(df$total_price_diff_from_lowest[df$Day_week == "Monday"], 
      main = 'Histogram for Monday', xlab = 'Price_Diff')
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213