Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ggplot2 running for minutes without plotting

I am attempting to plot the below vector, but when I run the function, it just continues to run and does not plot. I have waited 5 minutes before I feel uncomfortable and click stop in the console. Wondering what is going on. Up until this point I have had no trouble. While I am using facet_wrap with seven variables – there are only 56 rows and 4 columns so it doesn’t make sense why it would take so long.

See below dput() of my vector:

structure(list(`data_2021_v2$member_casual` = c("casual", "member", 
"casual", "member", "casual", "member", "casual", "member", "casual", 
"member", "casual", "member", "casual", "member", "casual", "member", 
"casual", "member", "casual", "member", "casual", "member", "casual", 
"member", "casual", "member", "casual", "member", "casual", "member", 
"casual", "member", "casual", "member", "casual", "member", "casual", 
"member", "casual", "member", "casual", "member", "casual", "member", 
"casual", "member", "casual", "member", "casual", "member", "casual", 
"member", "casual", "member", "casual", "member"), `data_2021_v2$time_of_day` = c(1, 
1, 2, 2, 3, 3, 4, 4, 1, 1, 2, 2, 3, 3, 4, 4, 1, 1, 2, 2, 3, 3, 
4, 4, 1, 1, 2, 2, 3, 3, 4, 4, 1, 1, 2, 2, 3, 3, 4, 4, 1, 1, 2, 
2, 3, 3, 4, 4, 1, 1, 2, 2, 3, 3, 4, 4), `data_2021_v2$day_of_week` = c("Friday", 
"Friday", "Friday", "Friday", "Friday", "Friday", "Friday", "Friday", 
"Monday", "Monday", "Monday", "Monday", "Monday", "Monday", "Monday", 
"Monday", "Saturday", "Saturday", "Saturday", "Saturday", "Saturday", 
"Saturday", "Saturday", "Saturday", "Sunday", "Sunday", "Sunday", 
"Sunday", "Sunday", "Sunday", "Sunday", "Sunday", "Thursday", 
"Thursday", "Thursday", "Thursday", "Thursday", "Thursday", "Thursday", 
"Thursday", "Tuesday", "Tuesday", "Tuesday", "Tuesday", "Tuesday", 
"Tuesday", "Tuesday", "Tuesday", "Wednesday", "Wednesday", "Wednesday", 
"Wednesday", "Wednesday", "Wednesday", "Wednesday", "Wednesday"
), `data_2021_v2$ride_length` = c(840, 584, 686, 526, 1023, 521, 
916, 610, 895, 545, 697, 530, 1125, 515, 971, 584, 906, 610, 
900, 594, 1194, 666, 1102, 673, 928, 590, 1002, 606, 1225, 676, 
1171, 670, 783, 556, 646, 521, 903, 495, 871, 590, 820, 544, 
652, 530, 962, 499, 891, 584, 814, 566, 647, 531, 920, 496, 874, 
591)), row.names = c(NA, -56L), class = "data.frame")

And below is the function I am using to plot:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ggplot(toddowrlmed, aes(factor(`data_2021_v2$time_of_day`, level=c(2,3,4,1)),
                        `data_2021_v2$ride_length`, fill=`data_2021_v2$member_casual`)) +
  facet_wrap(data_2021_v2$day_of_week) +
  geom_col(position = 'dodge')

And my sessionInfo():

    R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    
system code page: 65001

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] lubridate_1.8.0 forcats_0.5.1   stringr_1.4.0   dplyr_1.0.7     purrr_0.3.4     readr_2.1.2     tidyr_1.2.0    
 [8] tibble_3.1.6    ggplot2_3.3.5   tidyverse_1.3.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8       cellranger_1.1.0 pillar_1.7.0     compiler_4.1.2   dbplyr_2.1.1     tools_4.1.2     
 [7] digest_0.6.29    bit_4.0.4        jsonlite_1.7.3   lifecycle_1.0.1  gtable_0.3.0     pkgconfig_2.0.3 
[13] rlang_1.0.1      reprex_2.0.1     rstudioapi_0.13  DBI_1.1.2        cli_3.1.1        parallel_4.1.2  
[19] haven_2.4.3      xml2_1.3.3       withr_2.4.3      httr_1.4.2       fs_1.5.2         generics_0.1.2  
[25] vctrs_0.3.8      hms_1.1.1        bit64_4.0.5      grid_4.1.2       tidyselect_1.1.1 glue_1.6.1      
[31] R6_2.5.1         fansi_1.0.2      readxl_1.3.1     vroom_1.5.7      farver_2.1.0     tzdb_0.2.0      
[37] modelr_0.1.8     magrittr_2.0.2   backports_1.4.1  scales_1.1.1     ellipsis_0.3.2   rvest_1.0.2     
[43] assertthat_0.2.1 colorspace_2.0-2 labeling_0.4.2   utf8_1.2.2       stringi_1.7.6    munsell_0.5.0   
[49] broom_0.7.12     crayon_1.4.2

My laptop is brand new and relatively powerful with an intel i7 and 16GB ram, so I can’t imagine its a "processing power" issue. Thank you.

>Solution :

Your facet_wrap() call does not look correct, and you have some difficult-to-work-with column names. I named your dput structure dat, and gave it column names, and ran your plot with the facet_wrap correction, like this:

colnames(dat) = c("member_casual", "time_of_day", "day_of_week", "ride_length")

ggplot(dat, aes(factor(time_of_day, level=c(2,3,4,1)),
                ride_length,
                fill=member_casual)) +
  facet_wrap(~day_of_week) +
  geom_col(position = 'dodge')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading