#====================================== #========= EDIT THESE VALUES ========== #====================================== #define custom colors using hexadecimal notation colors <- c("virusA" = "#34b7eb", "virusB" = "#bf8c15") #====================================== # === THE CODE BELOW IS READY TO GO === #====================================== #load graphics library library(ggplot2) #load data organization library library(tibble) #load the data #timeline week<-c(1,2,3,4,5,6,7,8,9,10) #infections from virus type A and type B virusA<-c(0,1,1,4,5,8,18,23,96,137) virusB<-c(0,1,5,8,27,36,95,133,201,288) #store data as a tibble data<-tibble("week" = week, "virusA" = virusA, "virusB" = virusB) #print some data head(data) #line plot #ggplot(data, aes(x=week)) + # geom_line(aes(y = virusA, color="virusA"), linetype="solid") + # geom_line(aes(y = virusB, color="virusB"), linetype="solid") + # theme_minimal()+ # labs(x = "Date", # y = "Number of Infections", # color = "Legend") + # ggtitle("Infection Count from Virus A and Virus B over 10 weeks")+ # theme(axis.text.x = element_text(angle = 0, hjust = 1))+ # scale_color_manual(values = colors)+ # scale_x_continuous(breaks=seq(1, 10, 1)) #bar chart #do some data organization to get total values first totals<-c(sum(virusA), sum(virusB)) names<-c("A", "B") tbl<-tibble("total" = totals, "name" = names) #initialize bar chart bar<-ggplot(data=tbl, aes(x=name, y=total)) + geom_bar(stat="identity", fill="#34b7eb")+ coord_flip()+ theme_minimal()+ labs(x = "Virus Type", y = "Total Number of Infections at 10 weeks") bar
Change the variable values to your own measured values.