etc5523-2020 / exercise2C

For students to submit their reproducible example in the issue
0 stars 0 forks source link

How to plot a line graph and solve the overlapping problem on x-axis #38

Open yezihe-0063 opened 4 years ago

yezihe-0063 commented 4 years ago

I have the following data set and I want to create a line graph.

I used the geom_line code, but it doesn't work. And the dates on the x-axis are overlapping. Is there any way to solve these problems?

count_date1  <- tribble(~Date, ~freq,
                        "28-06-2015", 27,
                        "29-04-2015", 22,
                        "29-05-2015", 14,
                        "29-06-2015", 51,
                        "30-04-2015", 24,
                        "30-05-2015", 9,
                        "30-06-2015", 53,
                        "31-05-2015", 10,
                        "4/1/2015", 18,
                        "4/10/2015", 21,
                        "4/11/2015", 5,
                        "4/12/2015", 15,
                        "4/2/2015", 27,
                        "4/7/2015", 15,
                        "4/4/2015", 12,
                        "4/5/2015", 6)
#> Error in tribble(~Date, ~freq, "28-06-2015", 27, "29-04-2015", 22, "29-05-2015", : could not find function "tribble"

ggplot(count_date1, aes(Date,freq)) + 
  geom_point() + 
  geom_line(aes(group=Date)) +
  xlab("Date") + 
  ylab("No. of Complaints")
#> Error in ggplot(count_date1, aes(Date, freq)): could not find function "ggplot"

Created on 2020-08-14 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 3.6.3 (2020-02-29) #> os macOS Catalina 10.15.5 #> system x86_64, darwin15.6.0 #> ui X11 #> language (EN) #> collate en_AU.UTF-8 #> ctype en_AU.UTF-8 #> tz Australia/Melbourne #> date 2020-08-14 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0) #> backports 1.1.7 2020-05-13 [1] CRAN (R 3.6.2) #> callr 3.4.3 2020-03-28 [1] CRAN (R 3.6.2) #> cli 2.0.2 2020-02-28 [1] CRAN (R 3.6.0) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0) #> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0) #> devtools 2.3.0 2020-04-10 [1] CRAN (R 3.6.2) #> digest 0.6.25 2020-02-23 [1] CRAN (R 3.6.0) #> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 3.6.2) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.0) #> fs 1.4.1 2020-04-04 [1] CRAN (R 3.6.2) #> glue 1.4.1 2020-05-13 [1] CRAN (R 3.6.2) #> highr 0.8 2019-03-20 [1] CRAN (R 3.6.0) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.0) #> knitr 1.28 2020-02-06 [1] CRAN (R 3.6.0) #> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.0) #> pkgbuild 1.0.8 2020-05-07 [1] CRAN (R 3.6.2) #> pkgload 1.1.0 2020-05-29 [1] CRAN (R 3.6.2) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.0) #> processx 3.4.2 2020-02-09 [1] CRAN (R 3.6.0) #> ps 1.3.3 2020-05-08 [1] CRAN (R 3.6.2) #> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.0) #> Rcpp 1.0.4.6 2020-04-09 [1] CRAN (R 3.6.3) #> remotes 2.1.1 2020-02-15 [1] CRAN (R 3.6.0) #> rlang 0.4.6 2020-05-02 [1] CRAN (R 3.6.2) #> rmarkdown 2.3 2020-06-18 [1] CRAN (R 3.6.2) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0) #> stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0) #> testthat 2.3.2 2020-03-02 [1] CRAN (R 3.6.0) #> usethis 1.6.1 2020-04-29 [1] CRAN (R 3.6.2) #> withr 2.2.0 2020-04-20 [1] CRAN (R 3.6.2) #> xfun 0.13 2020-04-13 [1] CRAN (R 3.6.3) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.0) #> #> [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library ```

image

dullhunk commented 2 years ago

I had a similar problem, it may be caused by the fact that you need to remember to call library(tidyverse)

without that you can't use tribble @yezihe-0063