Struggling to create a scatter plot with time span

Hey guys, I'm new here and kinda noob in R, anyway I'm sorry if this is too silly, but I have been strugling to create a scatter plot from my data frame. To be more clear I'm using lubridate to measure time between the beggining to sentence of a lawsuit, in regular courts to specialized courts, now I want to put every case and it time span in a graph.

I would like to put this in a scatter plot, but I keep failing. I learned to do a scatter plot (ggplot2) on R following the example in the online book "R for data science", but in that example the data frame have names on its columns and rows.

So I tried to put names on my data frame, and failed again. So any ideias of how could I do it?

If it's not clear I apologize, just let me now so I can elaborate.

Thanks for your time.

library(readxl)
#> Warning: package 'readxl' was built under R version 3.4.4
setwd("D:/Alan/UFRGS/Projetos RStudio")
Tabela_Tempo_Julgamento <- read_excel("Tabela Tempo Julgamento.xlsx", 
                                      col_types = c("date", "date", "date", 
                                                    "date", "text", "text"))
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in A32 / R32C1: got '08.05.2017'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in D49 / R49C4: got '23.02.0107'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in A50 / R50C1: got '18.08.2016'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in A60 / R60C1: got '29.08.2016'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in D78 / R78C4: got '13.07.2016'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in A80 / R80C1: got '03.05.2017'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in D180 / R180C4: got '08.11.2016'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in C247 / R247C3: got '11.07.2015'
BD_especializadas <- read_excel("BD especializadas.xlsx", 
                                col_types = c("text", "text", "text", 
                                              "numeric", "date", "numeric", "date", 
                                              "text", "text", "text", "text", "text"))
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting numeric in F3 / R3C6: got 'N/A'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in G3 / R3C7: got 'N/A'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting numeric in F12 / R12C6: got 'N/A'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in G12 / R12C7: got 'N/A'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting numeric in F29 / R29C6: got 'N/A'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in G29 / R29C7: got 'N/A'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting numeric in F38 / R38C6: got 'N/A'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in G38 / R38C7: got 'N/A'

library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#> 
#>     date
as.Date(Tabela_Tempo_Julgamento$DataDistACR)
#>   [1] "2017-05-22" "2017-07-11" "2017-05-22" "2017-09-11" "2017-04-06"
#>   [6] "2016-07-14" "2017-10-04" "2017-08-03" "2017-06-19" "2017-08-25"
#>  [11] "2017-08-28" "2017-05-02" "2014-02-20" "2017-05-22" "2017-05-26"
#>  [16] "2017-06-12" "2017-04-20" "2016-11-07" "2017-05-05" "2017-02-06"
#>  [21] "2016-12-19" "2016-06-14" "2017-07-31" "2017-07-29" "2017-01-24"
#>  [26] "2016-06-16" "2016-06-07" "2015-10-15" "2017-08-24" "2017-06-01"
#>  [31] NA           "2017-05-05" "2017-04-26" "2017-04-11" "2017-02-02"
#>  [36] "2017-04-26" "2013-01-08" "2010-04-19" "2017-02-21" "2016-12-12"
#>  [41] "2016-03-14" "2016-03-14" "2017-07-07" "2017-06-28" "2017-08-02"
#>  [46] "2017-02-20" "2017-02-20" "2017-04-20" NA           "2017-03-08"
#>  [51] "2013-03-18" "2017-04-25" "2017-04-25" "2016-05-31" "2016-05-12"
#>  [56] "2017-01-20" "2017-05-22" NA           NA           "2014-11-28"
#>  [61] "2015-01-08" "2017-05-03" "2016-08-31" "2016-06-27" "2016-11-04"
#>  [66] "2016-06-20" "2017-05-10" "2016-04-29" "2016-08-24" "2016-06-24"
#>  [71] "2016-05-03" "2016-03-21" "2017-06-26" "2016-08-26" "2017-03-27"
#>  [76] "2012-02-20" "2016-10-17" "2017-04-24" NA           "2016-08-29"
#>  [81] "2017-04-15" "2017-05-04" "2017-02-20" "2017-04-20" "2017-03-30"
#>  [86] "2017-02-25" "2016-06-27" "2016-07-25" "2016-09-16" "2017-05-04"
#>  [91] "2017-04-27" "2016-09-08" "2017-05-24" "2016-11-04" "2016-08-15"
#>  [96] "2016-11-23" "2016-11-04" "2016-08-15" "2016-11-23" "2015-11-30"
#> [101] "2016-08-29" "2016-05-17" "2016-03-30" "2016-12-12" "2017-02-14"
#> [106] "2015-10-08" "2017-03-07" "2017-03-14" "2017-04-20" "2017-05-05"
#> [111] "2017-02-01" "2017-03-23" "2017-03-16" "2016-06-14" "2017-03-01"
#> [116] "2016-08-02" "2016-05-23" "2016-08-15" "2017-05-03" "2016-08-15"
#> [121] "2016-10-24" "2016-09-27" "2017-02-17" "2017-05-31" "2016-08-30"
#> [126] "2016-09-28" "2016-07-13" "2016-06-20" "2017-04-27" "2015-11-11"
#> [131] "2017-02-20" "2017-03-13" "2017-02-22" "2016-08-19" "2016-09-29"
#> [136] "2016-10-19" "2016-10-19" "2017-04-18" "2016-04-25" "2017-03-30"
#> [141] "2014-06-12" "2016-07-06" "2016-10-19" "2016-01-19" "2016-01-19"
#> [146] "2017-03-08" "2016-06-22" "2016-04-06" "2016-10-24" "2017-03-07"
#> [151] "2015-11-27" "2015-11-27" "2016-06-24" "2017-03-30" "2016-03-17"
#> [156] "2017-01-23" "2017-03-30" "2016-10-17" "2015-08-14" "2017-03-15"
#> [161] "2016-11-11" "2017-02-03" "2017-06-02" "2016-06-10" "2017-02-13"
#> [166] "2016-04-22" "2016-09-27" "2015-12-02" "2016-03-08" "2017-02-13"
#> [171] "2016-08-05" "2016-08-08" "2017-04-18" "2017-04-03" "2016-03-17"
#> [176] "2016-11-28" "2017-03-03" "2017-03-20" "2016-12-09" "2016-11-22"
#> [181] "2017-01-09" "2016-05-02" "2016-11-18" "2016-10-05" "2016-07-27"
#> [186] "2016-06-23" "2017-03-08" "2017-03-09" "2017-03-01" "2017-03-20"
#> [191] "2017-02-01" "2016-07-14" "2016-05-03" "2016-10-21" "2016-12-02"
#> [196] "2016-05-02" "2016-05-03" "2016-10-21" "2016-12-02" "2016-05-02"
#> [201] "2016-05-02" "2016-12-02" "2016-07-15" "2013-11-28" "2016-09-28"
#> [206] "2016-10-11" "2016-09-21" "2016-10-10" "2016-09-19" "2016-11-21"
#> [211] "2016-11-23" "2016-07-11" "2016-06-28" "2017-01-27" "2016-08-24"
#> [216] "2016-10-14" "2017-02-09" "2017-02-08" NA           "2016-10-26"
#> [221] "2015-11-18" "2016-11-07" "2016-12-07" "2016-07-28" "2016-08-15"
#> [226] "2016-11-22" "2016-02-18" "2017-02-01" "2015-11-18" "2016-12-01"
#> [231] "2016-01-27" "2016-03-28" "2013-06-06" "2015-11-18" "2015-06-19"
#> [236] "2016-03-29" "2015-08-20" "2016-10-06" "2016-12-06" "2016-02-25"
#> [241] "2016-11-18" "2014-03-19" "2014-03-11" "2016-02-24" "2016-10-20"
#> [246] "2016-11-04" "2016-09-26" "2016-06-20" "2016-11-24" "2017-01-17"
#> [251] "2016-10-25" "2016-09-26" "2016-01-29" "2013-09-10" "2016-10-20"
#> [256] "2016-09-20" "2016-10-07" "2016-04-06" "2016-08-19" "2016-09-01"
#> [261] "2016-02-05" "2016-10-20" "2016-07-08" "2016-08-04" "2016-06-13"
#> [266] "2016-10-28" "2016-08-24" "2016-11-07" "2016-09-01" "2016-06-21"
#> [271] "2016-06-21" "2015-05-07" "2015-12-03" "2016-11-21" "2016-09-05"
#> [276] "2016-10-19" "2016-10-06" "2016-10-13" "2015-12-14" "2015-12-02"
#> [281] "2015-09-08" "2016-02-11" "2016-03-08" "2016-09-20" "2015-06-26"
#> [286] "2016-12-06" "2016-09-28" "2016-07-27" "2016-07-20" "2015-05-18"
#> [291] "2016-11-16" "2015-11-30" "2015-10-19" "2014-07-25" "2016-07-29"
#> [296] "2016-07-15" "2015-11-16" "2016-03-02"
as.Date(Tabela_Tempo_Julgamento$DataJulgACR)  
#>   [1] "2017-12-13" "2017-12-13" "2017-12-13" "2017-12-13" "2017-12-13"
#>   [6] "2017-12-13" "2017-12-12" "2017-12-12" "2017-12-05" "2017-12-05"
#>  [11] "2017-12-05" "2017-12-05" "2017-11-28" "2017-11-28" "2017-11-28"
#>  [16] "2017-11-28" "2017-11-28" "2017-11-28" "2017-11-28" "2017-11-28"
#>  [21] "2017-11-28" "2017-10-17" "2017-11-22" "2017-11-22" "2017-11-22"
#>  [26] "2017-11-22" "2017-11-22" "2017-11-27" "2017-11-21" "2017-11-21"
#>  [31] "2017-11-21" "2017-11-21" "2017-11-22" "2017-11-07" "2017-10-19"
#>  [36] "2017-11-07" "2017-08-22" "2017-11-07" "2017-11-07" "2017-11-07"
#>  [41] "2017-11-07" "2017-11-07" "2017-11-07" "2017-11-07" "2017-11-07"
#>  [46] "2017-10-25" "2017-12-13" "2017-10-19" "2017-10-10" "2017-09-26"
#>  [51] "2017-10-11" "2017-10-11" NA           "2017-10-10" "2017-10-10"
#>  [56] "2017-10-10" "2017-10-10" "2017-10-10" "2017-09-13" "2017-09-26"
#>  [61] "2017-09-26" "2017-09-26" "2017-09-26" "2017-11-28" "2017-08-22"
#>  [66] "2017-09-19" "2017-09-19" "2017-09-19" "2017-09-19" "2017-09-19"
#>  [71] "2017-11-28" "2017-09-13" "2017-09-12" "2017-09-12" "2017-09-12"
#>  [76] "2017-09-12" "2017-09-06" "2017-09-06" "2017-09-06" "2018-04-19"
#>  [81] "2017-08-30" "2017-08-30" "2017-08-30" "2017-08-30" "2017-08-30"
#>  [86] "2017-08-30" "2017-08-29" "2017-08-29" "2017-08-29" "2017-08-23"
#>  [91] "2017-08-23" "2017-08-23" "2017-08-22" "2017-08-22" "2017-08-22"
#>  [96] "2017-08-22" "2017-08-22" "2017-08-22" "2017-08-22" "2017-08-16"
#> [101] "2017-08-16" "2017-08-16" "2017-08-16" "2017-10-10" "2017-08-16"
#> [106] "2017-08-15" "2017-08-15" "2017-08-15" "2017-08-09" "2017-08-09"
#> [111] "2017-08-09" "2017-08-09" "2017-08-09" "2017-08-08" "2017-08-08"
#> [116] "2017-08-02" "2017-08-02" "2017-08-02" "2017-08-01" "2017-08-01"
#> [121] "2017-08-01" "2017-08-01" "2017-07-25" "2017-07-25" "2017-07-19"
#> [126] "2017-07-18" "2017-07-18" "2017-07-18" "2017-07-18" "2017-07-12"
#> [131] "2017-07-05" "2017-07-25" "2017-07-06" "2017-07-05" "2017-07-05"
#> [136] "2017-07-05" "2017-07-05" "2017-07-04" "2017-07-04" "2017-06-27"
#> [141] "2017-06-27" "2017-06-14" "2017-07-05" "2017-06-30" "2017-06-30"
#> [146] "2017-06-27" "2017-06-21" "2017-06-21" "2017-06-21" "2017-06-21"
#> [151] "2017-06-20" "2017-06-20" "2017-07-07" "2017-06-20" "2017-06-20"
#> [156] "2017-06-20" "2017-06-14" "2017-06-14" "2017-06-14" "2017-06-14"
#> [161] "2017-06-14" "2017-06-14" "2017-06-06" "2017-06-06" "2017-06-06"
#> [166] "2017-06-06" "2017-06-06" "2017-05-31" "2017-05-30" "2017-05-30"
#> [171] "2017-05-30" "2017-05-30" "2017-05-30" "2017-05-30" "2017-05-24"
#> [176] "2017-05-24" "2017-05-23" "2017-05-23" "2017-05-17" "2017-05-17"
#> [181] "2017-05-17" "2016-05-02" "2017-05-17" "2017-05-17" "2017-05-16"
#> [186] "2017-05-16" "2017-05-16" "2017-05-16" "2017-05-16" "2017-05-16"
#> [191] "2017-05-10" "2017-05-10" "2017-04-26" "2017-04-26" "2017-04-26"
#> [196] "2017-04-25" "2017-04-26" "2017-04-26" "2017-04-26" "2017-04-25"
#> [201] "2017-04-25" "2017-04-25" "2017-04-19" "2017-04-19" "2017-04-19"
#> [206] "2017-04-19" "2017-04-19" "2017-04-19" "2017-04-19" "2017-04-19"
#> [211] "2017-04-18" "2017-04-18" "2017-04-18" "2017-04-18" "2017-04-11"
#> [216] "2017-04-11" "2017-04-11" "2017-04-11" "2017-04-06" "2017-04-05"
#> [221] "2017-04-05" "2017-04-05" "2017-04-05" "2017-04-05" "2017-04-04"
#> [226] "2017-04-04" "2017-04-04" "2017-04-04" "2017-04-04" "2017-04-04"
#> [231] "2017-03-29" "2017-03-29" "2017-03-29" "2017-03-29" "2017-03-29"
#> [236] "2017-03-29" "2017-03-29" "2017-03-28" "2017-03-28" "2017-03-28"
#> [241] "2017-03-22" "2017-03-22" "2017-03-22" "2017-03-22" "2017-03-22"
#> [246] "2017-03-22" "2017-03-22" "2017-03-15" "2017-03-15" "2017-03-15"
#> [251] "2017-03-15" "2017-03-15" "2017-03-15" "2017-03-15" "2017-03-15"
#> [256] "2017-03-08" "2017-03-08" "2017-03-08" "2017-03-08" "2017-03-08"
#> [261] "2017-03-08" "2017-03-06" "2017-03-06" "2017-03-06" "2017-03-06"
#> [266] "2017-02-22" "2017-02-22" "2017-02-22" "2017-02-21" "2017-02-21"
#> [271] "2017-02-21" "2017-02-21" "2017-02-21" "2017-02-21" "2017-02-15"
#> [276] "2017-02-15" "2017-02-15" "2017-02-15" "2017-02-15" "2017-02-15"
#> [281] "2017-02-15" "2017-02-14" "2017-02-08" "2017-02-08" "2017-02-07"
#> [286] "2017-02-07" "2017-02-01" "2017-02-01" "2017-02-01" "2017-01-31"
#> [291] "2017-01-31" "2017-01-31" "2017-01-25" "2017-01-25" "2017-01-25"
#> [296] "2017-01-25" "2017-01-25" "2017-01-24"
as.Date(Tabela_Tempo_Julgamento$DataDistDenuncia)  
#>   [1] "2015-09-11" "2015-07-28" "2015-09-11" "2017-07-25" "2005-06-17"
#>   [6] "2014-04-28" "2016-03-01" "2016-06-11" "2015-06-17" "2017-08-21"
#>  [11] "2017-02-24" "2015-12-09" "2013-11-06" "2000-06-14" NA          
#>  [16] "2015-12-26" "2014-10-17" "2014-07-30" "2014-02-21" "2015-06-03"
#>  [21] "2015-02-02" "2014-09-23" "2015-08-07" "2016-08-10" "2015-05-18"
#>  [26] "2010-07-22" "2014-02-03" "2013-10-16" "2017-06-13" "2016-10-10"
#>  [31] "2017-05-08" "2015-10-27" "2016-07-10" "2016-07-12" "2016-05-06"
#>  [36] "2016-03-26" NA           "2002-05-20" "2015-09-01" "2012-10-16"
#>  [41] NA           NA           "2016-05-24" "2015-07-21" "2014-01-16"
#>  [46] "2015-02-06" "2016-06-23" "2011-09-12" "2015-12-22" "2013-01-01"
#>  [51] "2005-07-06" "2013-02-18" NA           "2013-08-28" "2012-03-22"
#>  [56] "2016-03-03" "2016-10-15" "2012-01-25" "2015-09-04" "2012-06-22"
#>  [61] "2010-01-28" "2013-09-04" "2014-03-24" "2013-07-22" "2012-08-29"
#>  [66] "2012-06-19" "2014-07-24" "2014-04-25" "2011-12-13" "2013-07-22"
#>  [71] "2015-05-14" "2014-10-17" "2016-12-13" "2012-03-12" "2016-10-13"
#>  [76] "2008-03-10" "2016-05-11" NA           "2014-02-24" "2015-09-04"
#>  [81] "2016-05-05" "2015-06-30" "2011-11-11" "2015-07-20" "2010-05-26"
#>  [86] "2015-03-02" "2012-03-13" "2012-03-13" "2016-02-24" "2015-01-21"
#>  [91] "2010-08-10" "2013-03-25" "2016-11-07" "2012-08-29" "2014-07-04"
#>  [96] "2014-02-14" "2012-08-29" "2014-07-04" "2014-02-14" "2012-12-07"
#> [101] "2014-09-22" "2013-04-10" "2014-12-11" "2013-06-12" "2011-10-25"
#> [106] "2014-04-15" "2015-03-25" "2015-01-13" "2016-11-28" "2016-11-22"
#> [111] "2016-10-24" "2014-09-30" "2016-03-01" "2015-04-08" "2016-01-14"
#> [116] "2014-10-03" "2015-08-10" "2015-06-10" "2013-10-16" "2013-11-08"
#> [121] "2013-07-26" "2014-08-28" "2013-06-05" "2013-01-24" "2012-03-29"
#> [126] "2014-09-30" "2013-07-10" "2011-09-28" "2011-12-13" "2009-10-29"
#> [131] "2016-11-03" "2015-11-05" "2011-02-22" "2012-06-19" "2013-11-06"
#> [136] "2015-09-01" "2015-09-01" "2014-12-01" "2016-01-19" "2016-11-07"
#> [141] "2013-06-14" "2009-03-24" "2015-09-01" "2015-03-16" "2015-03-16"
#> [146] "2016-04-04" "2013-03-19" "2014-12-11" "2016-07-29" "2014-12-12"
#> [151] "2015-01-14" "2015-01-14" NA           "2014-07-23" "2014-04-29"
#> [156] "2015-10-15" "2016-12-06" "2007-09-26" "2014-07-10" "2016-08-19"
#> [161] "2015-08-20" "2014-11-04" "2014-10-10" "2015-07-15" "2014-09-02"
#> [166] "2014-05-20" "2012-10-11" "2015-05-14" "2014-03-20" "2014-11-03"
#> [171] "2014-08-28" "2014-04-24" "2015-12-27" "2012-12-05" "2015-07-14"
#> [176] "2013-10-04" "2015-02-04" "2016-01-07" NA           "2015-10-14"
#> [181] "2008-04-18" "2008-06-16" "2015-07-30" "2015-08-27" "2010-11-26"
#> [186] "2013-12-20" "2016-03-09" "2014-08-20" "2016-05-02" "2016-01-14"
#> [191] "2015-04-17" "2016-01-25" "2015-09-11" "2014-09-10" "2015-05-22"
#> [196] "2014-12-05" "2015-09-11" "2014-09-10" "2015-05-22" "2014-12-05"
#> [201] "2014-12-05" "2010-10-20" "2014-09-29" "2008-11-19" "2015-07-22"
#> [206] "2015-10-20" "2012-12-13" "2015-04-16" "2016-02-05" "2015-03-26"
#> [211] "2010-10-20" "2013-11-28" "2015-08-07" "2015-02-06" "2014-09-30"
#> [216] "2014-10-14" "2015-09-17" "2014-06-20" NA           "2016-05-06"
#> [221] "2014-12-11" "2014-11-25" "2014-10-08" "2013-12-18" "2015-04-14"
#> [226] "2015-02-02" "2014-05-13" "2015-08-24" "2015-10-13" "2007-02-16"
#> [231] "2012-11-08" "2014-02-17" "2011-01-19" "2011-01-11" "2006-10-17"
#> [236] "2015-08-06" NA           "2015-06-05" "2014-12-03" "2011-12-20"
#> [241] "2008-05-16" "2009-08-10" "2007-07-09" "2014-10-07" "2013-07-01"
#> [246] NA           "2016-01-28" "2015-09-09" "2015-07-22" "2015-09-30"
#> [251] "2013-12-06" "2011-07-01" "2010-04-23" "2010-09-03" "2015-01-12"
#> [256] "2014-01-27" "2014-11-21" "2014-11-17" "2013-06-26" "2014-05-22"
#> [261] "2015-03-24" "2015-07-07" "2014-05-28" "2010-06-07" "2010-09-28"
#> [266] "2015-08-06" "2013-06-24" "2015-10-20" "2010-10-20" "2015-08-03"
#> [271] "2015-07-03" "2014-03-26" "2013-10-09" "2016-07-15" "2015-02-27"
#> [276] "2016-06-15" "2013-02-25" "2009-04-28" "2014-04-29" "2014-09-30"
#> [281] "2014-09-04" "2015-07-28" "2010-12-17" "2013-07-15" "2013-07-16"
#> [286] "2013-11-12" "2016-02-22" "2013-04-23" "2014-08-14" "2012-08-08"
#> [291] "2015-11-06" "2015-04-14" "2014-09-16" "2008-03-04" "2011-09-16"
#> [296] "2014-05-06" "2011-07-28" "2014-06-30"
as.Date(Tabela_Tempo_Julgamento$DataJulgDenuncia)
#>   [1] NA           "2017-03-30" NA           NA           NA          
#>   [6] NA           NA           NA           NA           NA          
#>  [11] NA           "2016-03-22" NA           "2016-12-19" NA          
#>  [16] NA           NA           NA           NA           "2015-06-18"
#>  [21] NA           NA           NA           NA           "2016-12-01"
#>  [26] "2015-10-26" "2015-11-30" "2015-05-17" "2017-08-02" "2017-03-30"
#>  [31] NA           "2017-05-19" "2017-04-10" "2017-02-07" "2016-10-13"
#>  [36] "2017-02-02" NA           "2010-10-21" "2017-01-13" "2016-06-13"
#>  [41] NA           NA           "2017-04-10" "2017-06-08" "2017-05-10"
#>  [46] "2016-09-30" "2016-12-02" NA           "2016-05-09" "2016-10-26"
#>  [51] "2012-05-18" "2016-04-07" NA           "2016-03-31" "2016-03-21"
#>  [56] "2016-10-19" "2017-03-03" "2015-06-18" "2016-05-18" "2014-10-27"
#>  [61] "2014-11-14" "2016-07-11" "2016-07-19" "2016-01-08" "2016-10-14"
#>  [66] "2016-02-22" NA           "2015-06-15" "2015-12-06" "2016-06-03"
#>  [71] "2015-10-29" "2015-05-22" "2017-05-19" "2016-06-02" "2017-02-11"
#>  [76] NA           NA           NA           "2016-11-22" "2016-05-18"
#>  [81] "2017-03-31" "2017-02-09" "2016-10-04" "2017-03-01" "2016-09-22"
#>  [86] "2016-08-24" "2016-01-19" "2016-01-19" "2016-09-06" "2016-10-18"
#>  [91] "2017-02-07" "2015-12-04" "2017-04-13" "2016-10-14" "2016-06-12"
#>  [96] "2016-09-08" "2016-10-14" "2017-09-21" "2016-09-08" "2015-06-29"
#> [101] "2016-02-15" "2016-02-17" "2015-11-03" "2016-11-16" "2017-11-29"
#> [106] "2015-07-17" "2016-12-19" "2017-02-13" "2017-03-30" "2017-03-24"
#> [111] "2016-12-09" NA           "2017-02-20" "2016-05-09" "2017-01-12"
#> [116] "2016-05-25" "2016-02-01" "2016-06-23" "2016-06-03" "2015-05-27"
#> [121] "2016-08-10" "2016-08-11" "2016-11-17" "2017-02-23" "2016-02-04"
#> [126] "2016-08-08" "2016-03-17" "2015-09-15" "2016-10-28" "2013-12-18"
#> [131] "2017-01-15" "2017-02-09" "2016-05-30" "2016-06-13" "2016-08-04"
#> [136] "2016-09-30" "2016-09-30" "2017-02-01" NA           "2017-02-22"
#> [141] "2014-05-22" "2016-04-20" "2016-09-30" "2015-09-21" "2015-09-21"
#> [146] "2017-01-17" "2016-05-05" "2015-12-14" "2016-09-23" "2016-10-28"
#> [151] "2015-10-03" "2015-10-03" NA           "2017-02-22" "2015-12-11"
#> [156] "2016-09-27" "2017-02-22" "2016-05-23" "2015-06-26" "2017-02-02"
#> [161] "2016-10-10" "2016-09-23" "2017-03-15" "2016-04-22" "2017-01-18"
#> [166] "2015-10-01" "2016-07-01" "2015-09-22" "2015-12-17" "2016-12-04"
#> [171] "2016-04-14" "2016-06-12" "2016-12-16" "2017-02-13" "2015-10-09"
#> [176] "2016-10-06" "2016-12-12" "2017-02-10" NA           "2016-09-13"
#> [181] "2015-05-29" "2015-10-07" "2016-07-11" "2016-06-23" "2013-05-14"
#> [186] "2016-03-09" "2017-01-25" "2016-12-19" "2016-11-22" "2017-01-18"
#> [191] "2016-10-06" "2016-04-19" "2016-03-10" "2016-09-09" "2016-11-18"
#> [196] "2015-12-18" "2016-03-10" "2016-09-09" "2016-11-18" "2015-12-18"
#> [201] "2015-12-18" "2016-06-09" "2016-04-11" "2013-08-15" "2016-08-28"
#> [206] "2016-08-10" "2016-04-01" "2016-09-08" "2016-06-22" "2016-09-01"
#> [211] "2016-06-09" "2016-03-03" "2016-04-06" "2016-09-30" "2016-07-01"
#> [216] "2016-04-01" "2016-11-24" "2015-09-16" NA           "2016-09-01"
#> [221] "2015-07-20" "2016-09-01" "2016-09-21" "2016-07-04" "2016-04-27"
#> [226] "2016-08-02" "2015-11-24" "2016-11-09" "2015-10-21" "2015-12-15"
#> [231] "2016-01-18" "2015-09-22" "2013-04-03" "2015-02-25" "2015-03-12"
#> [236] "2015-10-16" NA           "2016-05-17" "2016-10-24" "2015-07-06"
#> [241] "2016-10-07" "2013-07-17" "2013-05-02" "2015-07-08" "2016-04-05"
#> [246] "2016-08-02" "2016-08-22" "2018-02-18" "2016-08-18" "2016-10-10"
#> [251] "2016-09-14" "2016-02-11" "2015-02-09" "2013-04-02" "2016-09-09"
#> [256] NA           "2016-08-30" "2016-02-26" "2016-07-18" "2016-06-27"
#> [261] "2015-06-25" "2016-06-09" "2015-11-05" "2015-12-03" "2016-04-04"
#> [266] "2016-10-04" "2016-05-30" "2016-09-23" "2016-06-09" "2016-03-08"
#> [271] "2016-03-08" "2014-10-15" "2015-01-20" "2016-09-15" "2016-07-30"
#> [276] NA           "2016-08-24" "2016-05-05" "2015-11-10" "2015-07-17"
#> [281] "2015-03-24" "2016-09-19" "2015-03-18" "2016-08-17" "2015-02-13"
#> [286] "2016-02-23" "2016-08-28" "2016-05-13" "2016-05-11" "2015-01-26"
#> [291] "2016-09-27" "2015-09-17" "2015-09-03" "2013-11-25" "2015-09-25"
#> [296] "2016-05-20" "2015-05-07" "2015-04-07"

#Measuring the interval between the begining of a trial to its end
JULG2 <- interval(Tabela_Tempo_Julgamento$DataDistACR, Tabela_Tempo_Julgamento$DataJulgACR)

JULG1 <- interval(Tabela_Tempo_Julgamento$DataDistDenuncia, Tabela_Tempo_Julgamento$DataJulgDenuncia)

JULG1 <- as.data.frame(as.period(JULG1))
summary(JULG1)
#>  as.period(JULG1)                        
#>  Min.   :8d 0H 0M 0S                     
#>  1st Qu.:328d 21H 0M 0S                  
#>  Median :595d 7H 30M 0S                  
#>  Mean   :823d 8H 52M 0.463320463895798S  
#>  3rd Qu.:1116d 18H 0M 0S                 
#>  Max.   :6031d 15H 0M 0S                 
#>  NA's   :39

JULG2 <- as.data.frame(as.period(JULG2))
summary(JULG2)
#>  as.period(JULG2)                      
#>  Min.   :0S                            
#>  1st Qu.:139d 18H 0M 0S                
#>  Median :231d 1H 30M 0S                
#>  Mean   :317d 2H 4M 1.23711340129375S  
#>  3rd Qu.:391d 6H 0M 0S                 
#>  Max.   :2758d 9H 0M 0S                
#>  NA's   :7

as.Date(BD_especializadas$DataDistDenuncia)
#>  [1] "2015-02-02" "2017-08-21" "2016-10-10" "2016-05-06" "2016-03-26"
#>  [6] "2016-06-23" "2015-09-04" "2012-06-22" "2014-03-24" "2015-05-14"
#> [11] "2008-03-10" "2015-09-04" "2014-12-11" "2016-03-01" "2014-10-03"
#> [16] "2015-08-10" "2015-06-10" "2013-11-06" "2015-03-16" "2015-03-16"
#> [21] "2014-12-11" "2015-01-14" "2015-01-14" "2014-10-10" "2015-05-14"
#> [26] "2014-12-11" "2008-05-16" "2016-06-15" "2016-07-29" "2014-07-10"
#> [31] "2012-08-08" "2015-09-01" "2015-09-01" "2015-09-01" "2013-09-04"
#> [36] "2014-03-26" "2016-01-19" "2016-01-07" "2016-11-07" "2016-05-05"
#> [41] "2016-11-07" "2002-05-20" "2013-06-12" "2014-08-28" "2014-09-02"
#> [46] "2014-11-03" "2014-08-28" "2014-04-24" "2013-11-28" "2016-02-22"
#> [51] "2014-09-30" "2013-07-10" "2014-05-13" "2008-03-04"
as.Date(BD_especializadas$DataJulgDenuncia)
#>  [1] "2016-08-02" NA           "2017-03-30" "2016-10-13" "2017-02-02"
#>  [6] "2016-12-02" "2016-05-18" "2014-10-27" "2016-07-19" "2015-10-29"
#> [11] NA           "2016-05-18" "2015-11-03" "2017-02-20" "2016-05-25"
#> [16] "2016-02-01" "2016-06-23" "2016-08-04" "2015-09-21" "2015-09-21"
#> [21] "2015-12-14" "2015-10-03" "2015-10-03" "2017-03-15" "2015-09-22"
#> [26] "2015-07-20" "2016-10-07" NA           "2016-09-23" "2015-06-26"
#> [31] "2015-01-26" "2016-09-30" "2016-09-30" "2016-09-30" "2016-07-11"
#> [36] "2014-10-15" NA           "2017-02-10" "2017-04-13" "2017-03-31"
#> [41] "2017-02-22" "2010-10-21" "2016-11-16" "2016-08-11" "2017-01-18"
#> [46] "2016-12-04" "2016-04-14" "2016-06-12" "2016-03-03" "2016-08-28"
#> [51] "2016-08-08" "2016-03-17" "2015-11-24" "2013-11-25"
JULGesp <- interval(BD_especializadas$DataDistDenuncia, BD_especializadas$DataJulgDenuncia)

JULGesp <- as.data.frame(as.period(JULGesp))
summary(JULGesp)
#>  as.period(JULGesp)        
#>  Min.   :55d 10H 30M 0S    
#>  1st Qu.:206d 17H 37M 30S  
#>  Median :386d 6H 0M 0S     
#>  Mean   :604d 21H 30M 36S  
#>  3rd Qu.:814d 8H 15M 0S    
#>  Max.   :3075d 4H 30M 0S   
#>  NA's   :4

Hey @dillalan! I have some ideas, but it's a little hard to see the structure of your data when you're running off full columns this way. Are you able to just print head(mydata) or something, so we can see the first few rows of each column?

Speaking more generally, I don't think it's necessary to calculate intervals yourself. If you have a column for the start date and the end date, you should be able to use ggplot2's geom_errorbarh (or, with the ggalt package, geom_dumbbell) to plot these timespans.

For example, if I had this data:

library(tidyverse)
# generate some sample data with random dates
cases = data_frame(
  case_id = 1:5,
  start = as.Date('2018-01-01') + runif(5, min = 1, max = 60),
  finish = as.Date('2018-01-01') + runif(5, min = 70, max = 120))
cases
# A tibble: 5 x 3
#   case_id start      finish    
#     <int> <date>     <date>    
# 1       1 2018-02-28 2018-04-09
# 2       2 2018-02-18 2018-04-06
# 3       3 2018-01-26 2018-04-06
# 4       4 2018-02-24 2018-03-19
# 5       5 2018-02-24 2018-04-19

Then I could do a basic plot of the timespans like this:

library(ggalt)
ggplot(cases, aes(y = case_id)) +
  geom_dumbbell(aes(x = start, xend = finish)) +
  labs(
    x = 'Time',
    y = 'Case')
# note: if you don't have ggalt installed, geom_errorbarh works the same way
# but uses xmin and xmax instead of x and xend

Does that seem like the sort of thing you're looking for, or are you specifically looking to plot the case length against another variable in a scatter plot?

3 Likes

Hey @rensa thanks for your support and effort to understand my code. I'm placing the code that you asked, right above. So I want to plot an out put like Case 1 x 2y 2m (or 760 days), in a scatter plot. Thats why I calculate the interval, but I'll try your way.

library(readxl)
#> Warning: package 'readxl' was built under R version 3.4.4
setwd("D:/Alan/UFRGS/Projetos RStudio")
Tabela_Tempo_Julgamento <- read_excel("Tabela Tempo Julgamento.xlsx", 
                                      col_types = c("date", "date", "date", 
                                                    "date", "text", "text"))
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in A32 / R32C1: got '08.05.2017'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in D49 / R49C4: got '23.02.0107'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in A50 / R50C1: got '18.08.2016'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in A60 / R60C1: got '29.08.2016'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in D78 / R78C4: got '13.07.2016'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in A80 / R80C1: got '03.05.2017'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in D180 / R180C4: got '08.11.2016'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in C247 / R247C3: got '11.07.2015'

head(Tabela_Tempo_Julgamento)
#> # A tibble: 6 x 6
#>   DataDistACR         DataJulgACR         DataDistDenuncia   
#>   <dttm>              <dttm>              <dttm>             
#> 1 2017-05-22 00:00:00 2017-12-13 00:00:00 2015-09-11 00:00:00
#> 2 2017-07-11 00:00:00 2017-12-13 00:00:00 2015-07-28 00:00:00
#> 3 2017-05-22 00:00:00 2017-12-13 00:00:00 2015-09-11 00:00:00
#> 4 2017-09-11 00:00:00 2017-12-13 00:00:00 2017-07-25 00:00:00
#> 5 2017-04-06 00:00:00 2017-12-13 00:00:00 2005-06-17 00:00:00
#> 6 2016-07-14 00:00:00 2017-12-13 00:00:00 2014-04-28 00:00:00
#> # ... with 3 more variables: DataJulgDenuncia <dttm>, Comarca <chr>,
#> #   `1G-Competencia` <chr>

Created on 2018-09-11 by the reprex package (v0.2.0).

1 Like

So, in adition I tried the code that you suggested but I get an error. I dont know what value or thing that I have to atribute to "x".
EDIT: As you can see I added a column "ID" to adjust the data frame to your example

library(readxl)
#> Warning: package 'readxl' was built under R version 3.4.4
setwd("D:/Alan/UFRGS/Projetos RStudio")
library(readxl)
Tabela_Tempo_Julgamento <- read_excel("Tabela Tempo Julgamento.xlsx", 
                                      col_types = c("numeric", "date", "date", 
                                                    "date", "date", "text", "text"))
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in B32 / R32C2: got '08.05.2017'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in E49 / R49C5: got '23.02.0107'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in B50 / R50C2: got '18.08.2016'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in B60 / R60C2: got '29.08.2016'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in E78 / R78C5: got '13.07.2016'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in B80 / R80C2: got '03.05.2017'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in E180 / R180C5: got '08.11.2016'
#> Warning in read_fun(path = path, sheet_i = sheet, limits = limits, shim =
#> shim, : Expecting date in D247 / R247C4: got '11.07.2015'


head(Tabela_Tempo_Julgamento)
#> # A tibble: 6 x 7
#>      ID DataDistACR         DataJulgACR         DataDistDenuncia   
#>   <dbl> <dttm>              <dttm>              <dttm>             
#> 1    1. 2017-05-22 00:00:00 2017-12-13 00:00:00 2015-09-11 00:00:00
#> 2    2. 2017-07-11 00:00:00 2017-12-13 00:00:00 2015-07-28 00:00:00
#> 3    3. 2017-05-22 00:00:00 2017-12-13 00:00:00 2015-09-11 00:00:00
#> 4    4. 2017-09-11 00:00:00 2017-12-13 00:00:00 2017-07-25 00:00:00
#> 5    5. 2017-04-06 00:00:00 2017-12-13 00:00:00 2005-06-17 00:00:00
#> 6    6. 2016-07-14 00:00:00 2017-12-13 00:00:00 2014-04-28 00:00:00
#> # ... with 3 more variables: DataJulgDenuncia <dttm>, Comarca <chr>,
#> #   `1G-Competencia` <chr>


library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 3.4.4
ggplot(Tabela_Tempo_Julgamento, aes(y = Tabela_Tempo_Julgamento$ID )) +
  geom_errorbarh(aes(xmin =  Tabela_Tempo_Julgamento$DataDistACR, xmax = Tabela_Tempo_Julgamento$DataJulgACR)) +
  labs(
    x = 'Time',
    y = 'Case')
#> Error: geom_errorbarh requires the following missing aesthetics: x
1 Like

No worries, @dillalan :slight_smile: if you're making a reprex it generally helps us a lot for you to make the data available, but I think in this case it's enough that we can see the structure of your data frame.

The reason my example isn't working for you in that the x aesthetic isn't defined. geom_errorbarh only requires xmin and xmax (since the errorbar doesn't necessarily have a "middle"), but the plot still needs x. If you add x = DataDistACR to the aes() inside ggplot(), that should do the trick.

Also note that you don't need to prefix your column names with your data frame when building a ggplot2 plot—since you specify the data frame at the start with ggplot(Tabela_Tempo_Julgamento), you can (and should) just write things like y = ID, rather than y = Tabela_Tempo_Julgamento$ID.

If you want to plot the length of time between your start and end dates, I'm assuming you'll want to it using a single unit (number of days, or number of years), rather than using "x years, y months, z days" (which works well in text but not in a plot). If that's the case, you needn't bother with interval or as.period(): you can get the number of days by simply subtracting the start date from the end date. So you could do:

library(readxl)
setwd("D:/Alan/UFRGS/Projetos RStudio")
Tabela_Tempo_Julgamento <- read_excel("Tabela Tempo Julgamento.xlsx", 
                                      col_types = c("date", "date", "date", 
                                                    "date", "text", "text"))

# so if start date is DataDistACR and end date is DataJulgACR…
Tabela_Tempo_Julgamento$length =
  Tabela_Tempo_Julgamento$DataDistACR - Tabela_Tempo_Julgamento$DataJulgACR

And then length would be either your x or y inside ggplot's aes(). There's no need to convert the length between days and years if it's just for plotting; ggplot2 can intelligently do this if you add a scale_*() function to your plot.

If you want a scatter plot where case length is on one axis, what would you have on your other axis?

3 Likes

You sir are a hero. Thanks. Now I have my graph, sure I should do some changes to improve the visual, but the most important is that I have a graph to present the data.

Actually its Cases x Lenght.

Oh my... all the drama with lubridate :disappointed:
Well at least its more simple

Anyway I want to thank you again, for trying to understand what I wanted to do with that code. I'm happy to know that are people willing to help begginers like me. My mission now is to improve the graph (seems a little unfrendly, dont you think?).

image

1 Like

Not a problem! There's always room to polish up plots, and you might want to create a few different visualisations (for example, a barplot to see what typical and non-typical case lengths are like), but I think you have a good foundation to start tinkering now :smiley: Feel free to ask if you have any other questions!

Also, if you feel like I answered your original question, marking the topic as solved will help other users who have similar problems in future :slight_smile:

1 Like