Вы можете предоставить немного больше информации о том, что вы ищете. Но вот быстрый способ манипулировать данными и построить график с помощью пакета ggplot2.
# Libraries
library(ggplot2)
library(reshape2)
# Data
df <- data.frame("Hospital" = c("Buge Hospital", "Buge Hospital", "Greta Hospital", "Greta Hospital",
"Makor Hospital", "Makor Hospital"),
"Period" = c("Jul-18","Aug-18", "Jul-18","Aug-18", "Jul-18","Aug-18"),
"Medical admissions" = c(12,56,0,40,5,56),
"Surgical admissions" = c(10,2,0,50,20,56),
"Inpatient admissions" = c(9,5,6,0,60,96))
df
# Note, generally it's good not to have spaces in column names. But fyi, R will put a period where the space is.
# I also changed the hospital names to be consistent
# Melt data into long format
df_long <- melt(data = df,
id.vars = c("Hospital","Period"),
measure.vars = c("Medical.admissions", "Surgical.admissions", "Inpatient.admissions"))
# Plot with color as admission type and different panel for each hospital
ggplot(df_long, aes(x = Period, y = value,
colour = variable, group = variable)) +
geom_point() +
geom_line() +
scale_x_discrete(limits = rev(levels(df_long$Period))) +
labs(x = "Month", y = "Number of People", colour = "Type") +
facet_wrap(~ Hospital)
# Stacked barplot
ggplot(df_long, aes(x = Period, y = value,
fill = variable, group = variable)) +
geom_bar(stat = "identity") +
scale_x_discrete(limits = rev(levels(df_long$Period))) +
labs(x = "Month", y = "Number of People", fill = "Type") +
facet_wrap(~ Hospital)
# Dodged barplot
ggplot(df_long, aes(x = Period, y = value,
fill = variable, group = variable)) +
geom_bar(stat = "identity", position = "dodge") +
scale_x_discrete(limits = rev(levels(df_long$Period))) +
labs(x = "Month", y = "Number of People", fill = "Type") +
facet_wrap(~ Hospital)