-1
df1 <- data.frame(
  "Item" = c("20170315","20170316","20170409","20170411","20170525"),
  "Value" = c(400, 515, 743, 682, 458))

df2 <- data.frame(
  "Item" = c("20180102","20180227","20180311","20180318","20180522","20180628"),
  "Value" = c(793, 541, 777, 847, 901, 433))

Want to show two dataframe in one plot, like this picture. Have a nice day! enter image description here

Quinten
  • 35,235
  • 5
  • 20
  • 53
Alegría
  • 179
  • 5

1 Answers1

0

Like this?
Create a column cond and bind the data sets. Then it's a normal dodged bar plot.

df1 <- data.frame(
  "Item" = c("20170315","20170316","20170409","20170411","20170525"),
  "Value" = c(400, 515, 743, 682, 458))

df2 <- data.frame(
  "Item" = c("20180102","20180227","20180311","20180318","20180522","20180628"),
  "Value" = c(793, 541, 777, 847, 901, 433))

suppressPackageStartupMessages({
  library(dplyr)
  library(ggplot2)
})

bind_rows(
  df1 %>% mutate(cond = "A"),
  df2 %>% mutate(cond = "B")
) %>%
  ggplot(aes(Item, Value, fill = cond)) +
  geom_col() +
  theme(axis.text.x = element_text(angle = 60, vjust = 1, hjust=1))

Created on 2022-08-21 by the reprex package (v2.0.1)

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66