[R] Ggplot2 Line Problem

Stephen P. Molnar @@mo|n@r @end|ng |rom @bcg|ob@|@net
Mon Aug 17 03:00:58 CEST 2020


I have cobbled together a short script to plot Covid-19 data.

setwd("~/Apps/Models/1-CoronaVirus")

library(tidyverse)
library(lubridate)

datO <- read.csv("https://api.covidtracking.com/v1/states/oh/daily.csv")
datO[ ,1] <- ymd(datO[ ,1])

dfO <- tibble::as_tibble(data.frame(datO[ ,"date"],datO[ 
,"positive"],datO[ ,"negative"],datO[ ,"total"]))

dfO %>%
   ggplot(aes(x = datO[ ,"date"],y = datO[ ,"positive"]))+
   geom_point(color = 'red', size = 0.025)+
   geom_point(y = datO[ ,"negative"], color = 'blue', size = 0.025)+
   geom_point(y = datO[ ,"total"], color = "green", size = 0.025)+
   theme(axis.text.x = element_text(angle=30, hjust=1))+
   theme_bw()+
   scale_y_continuous(limits = c(0,1750000))+
   labs(x = "Date", y = "Number of Tests")+
   ggtitle("COVID-19 Tests in Ohio \n (8/15/20)")+
   theme(plot.title = element_text(hjust = 0.5))+
   scale_fill_discrete(name = "Test", labels = c("Positive", "Negative", 
"Total"))

Here is the plot:




but, if I want lines rather that the code (the aspplicable plines) uis:

ggplot(aes(x = datO[ ,"date"],y = datO[ ,"positive"]))+
   geom_line(linetype = "solid",color = 'red')+
   geom_line(linetype = "dotdash",y = datO[ ,"negative"], color = 'blue')+
   geom_line(linetype = "twodash",y = datO[ ,"total"], color = "green")+




Now two of the plots are reversed. Google has not been a friend in 
finding a solution.

Help will be much appreciated.

Thanks in advance

-- 
Stephen P. Molnar, Ph.D.
www.molecular-modeling.net
614.312.7528 (c)
Skype:  smolnar1



More information about the R-help mailing list