-1

I have the following data frame.

IN <- c(3.5, 5.75, 9, 13.25, 13, 9.5, 9.25, 6.75, 7, 4.25, 3.25, 1.75, 0)
OUT <- c(0.25, 2, 5.25, 8.5, 10.5, 11, 11.75, 9.25, 9.5, 7, 3.75, 4, 3.5)
dat <- data.frame(IN, OUT)
rownames(dat) <- c("10~11", "11~12", "12~13", "13~14", "14~15", "15~16", "16~17", "17~18", "18~19", "19~20", "20~21", "21~22", "22~23")

This data is the average number of people measured in restaurants four days per hour from 10:00 am to 11:00 pm. I want to use this data to plot the x-axis as time and the y-axis as the number of people. What should I do with r code?

소재룡
  • 31
  • 1
  • 4
  • Look at the ggplot documentation. It'll sort you out: https://ggplot2.tidyverse.org/reference/geom_bar.html – duffymo Jun 22 '18 at 14:26
  • Do you mean a Gantt ? Maybe [this](https://stackoverflow.com/questions/9862519/gantt-style-time-line-plot-in-base-r) can help – digEmAll Jun 22 '18 at 14:26

2 Answers2

0
barplot(height = dat$OUT, names.arg = row.names(dat))

Is the base version way to do this.

MDEWITT
  • 2,338
  • 2
  • 12
  • 23
0

If you need both IN and OUT plotted in the same plot, you can do that by changing up the data a little, as shown below:

library(ggplot2)
IN <- c(3.5, 5.75, 9, 13.25, 13, 9.5, 9.25, 6.75, 7, 4.25, 3.25, 1.75, 0)
OUT <- c(0.25, 2, 5.25, 8.5, 10.5, 11, 11.75, 9.25, 9.5, 7, 3.75, 4, 3.5)
type <-c(rep("IN", 13), rep("OUT", 13))
values <- c(IN, OUT)

foo <- c("10~11", "11~12", "12~13", "13~14", "14~15", "15~16", 
               "16~17", "17~18", "18~19", "19~20", "20~21", "21~22", "22~23")
dat <- data.frame(foo, values)
p <- ggplot(dat, aes(foo, values))
p + geom_bar(stat = "identity", aes(fill = type), position = "dodge")

enter image description here

Vishesh Shrivastav
  • 2,079
  • 2
  • 16
  • 34