rggplot2

How can I create A Simple plot in R?


I am an R novice.

I have been able to get my header-less data into columns:

my_data<- separate(my_data,col = "V1",into = c("Date", "Tool","Dept","Port","Host","Min","Max"),sep = ":")

It looks like this:

          Date   Tool         Dept  Port     Host Min Max
1: 03-Mar-2019 toolset Headquaters  1234 host.com   1   7
2: 10-Mar-2019 toolset Headquaters  1234 host.com   0   7
3: 17-Mar-2019 toolset Headquaters  1234 host.com   1   7

I plot it:

> p1 <- ggplot() + geom_line(aes(y = Max, x = Date),data = My_data)
> p1

But all I get is this:

enter image description here

How can I plot the min/max over time?

EDIT1: These are dates, not factors or anything else

EDIT2: I tried the suggestion:

my_data$Date <- as.Date(lmt$Date, "%d-%b-%Y")

and got newest


Solution

  • Here is your basic plot:

    My_data<-read.table(header=TRUE,, text="Date   Tool         Dept  Port     Host Min Max
    03-Mar-2019 toolset Headquaters  1234 host.com   1   7
    10-Mar-2019 toolset Headquaters  1234 host.com   0   7
    17-Mar-2019 toolset Headquaters  1234 host.com   1   7")
    
    My_data$Date <- as.Date(My_data$Date, "%d-%b-%Y")
    
    library(ggplot2)
    p1 <- ggplot(data=My_data, aes(x=Date)) + 
      geom_line(aes(y = Max), col="blue") +
      geom_line(aes(y = Min), col="green")
    print(p1)
    

    enter image description here