Hello plotly community,
I have two different data frames in RStudio that are similar, df2
and df4
, and when I try to create a grouped barplot, only one renders correctly.
> str(df2)
Classes ‘data.table’ and 'data.frame': 15 obs. of 4 variables:
$ Year : Factor w/ 5 levels "2006","2008",..: 1 2 3 4 5 1 2 3 4 5 ...
$ Race : Factor w/ 3 levels "White","Black",..: 1 1 1 1 1 2 2 2 2 2 ...
$ Internet: Factor w/ 2 levels "Has Internet",..: 1 1 1 1 1 1 1 1 1 1 ...
$ Percent : num 0.67 0.73 0.78 0.79 0.83 0.47 0.54 0.6 0.62 0.81 ...
- attr(*, ".internal.selfref")=<externalptr>
> str(df4)
Classes ‘data.table’ and 'data.frame': 15 obs. of 4 variables:
$ Year : Factor w/ 5 levels "2006","2008",..: 1 2 3 4 5 1 2 3 4 5 ...
$ Income : Factor w/ 3 levels "Less than $30k",..: 1 1 1 1 1 2 2 2 2 2 ...
$ Internet: Factor w/ 2 levels "Has Internet",..: 1 1 1 1 1 1 1 1 1 1 ...
$ Percent : num 0.4 0.44 0.56 0.53 0.62 0.62 0.7 0.79 0.84 0.85 ...
- attr(*, ".internal.selfref")=<externalptr>
When I use the following code on df2
, I get the intended output:
plot_ly(data = df2, x = ~Year, y = ~Percent, color = ~Race, type = "bar")
Using the same code on df4
, I get an empty plot.
plot_ly(data = df4, x = ~Year, y = ~Percent, color = ~Income, type = "bar")
Below is my sessionInfo output. I am running R on windows 10. Thanks for your help.
> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
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
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] htmltools_0.3.5 stargazer_5.2 htmlwidgets_0.7 RColorBrewer_1.1-2 plotly_4.5.2 data.table_1.9.6
[7] scales_0.4.0 ggplot2_2.1.0 dplyr_0.5.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.7 magrittr_1.5 devtools_1.12.0 munsell_0.4.3 colorspace_1.2-7 viridisLite_0.1.3
[7] R6_2.2.0 httr_1.2.1 plyr_1.8.4 tools_3.3.1 grid_3.3.1 gtable_0.2.0
[13] DBI_0.5-1 git2r_0.15.0 withr_1.0.2 yaml_2.1.13 lazyeval_0.2.0 assertthat_0.1
[19] digest_0.6.10 tibble_1.2 purrr_0.2.2 tidyr_0.6.0 base64enc_0.1-3 curl_2.2
[25] rsconnect_0.4.3 memoise_1.0.0 labeling_0.3 jsonlite_1.1 chron_2.3-47