hrbrmstr / statebins Goto Github PK
View Code? Open in Web Editor NEWAlternative to choropleths of US States ala http://bit.ly/statebins
License: Other
Alternative to choropleths of US States ala http://bit.ly/statebins
License: Other
Hi, the plot generating the color scale from the direction that is the opposite of what I want. Is there a simple way to reverse the color scale?
Right now the state abbreviations will not print if a value is NA
:
library(statebins)
library(dplyr)
data(USArrests)
USArrests$state <- rownames(USArrests)
USArrests$Assault[1] <- NA
statebins(USArrests, value_col="Assault", name = "Assault", round=TRUE) +
theme_statebins(legend_position="right")
Which returns this error:
1: In .sb_invert(gb$data[[1]]$fill, dark_label, light_label) :
NAs introduced by coercion
It would be nice to still have the abbreviation printed -- possibly with a user-specified color.
Is it possible to add a line chart to the statebins as shown in this JHU plot?
Hi there
Great package. I wondered if there was an easy way to resize different bins? I'm after resizing the bins by population size, like this:
https://brilliantmaps.com/us-territories-resized/
It seems like resizing might not be too hard, but wondered whether dodging so that there is no overlap might be a bit trickier?
Best
Alan
see http://stackoverflow.com/a/28122695/1273199
I get the error message "Error: state_data[, state_col] %in% state_coords[, merge.x] is not TRUE" when the data.frame is wrapped by the tbl_df class.
library(statebins)
t <- read.table(text= "year value state
2008 55.50628 Alabama
2008 67.52304 Alaska
2008 70.94418 Arizona
2008 57.89743 Arkansas
2008 71.40450 California
2008 75.29866 Colorado
2008 73.13052 Connecticut
2008 74.69418 Delaware",
header=TRUE, stringsAsFactors=FALSE)
class(t) # data.frame
statebins(t, state_col = "state", value_col = "value") # results in a statebins map
library(dplyr) # now repeat with tbl_df
t <- tbl_df(t) # convert to a tbl_df type
class(t) # "tbl_df" "tbl" "data.frame"
statebins(t, state_col = "state", value_col = "value") # yields this error message: "Error: state_data[, state_col] %in% state_coords[, merge.x] is not TRUE"
The help file states that the legend_position can be in the following positions...
legend_position | "none", "top", "left", "right" or "bottom" (defaults to "top")
But, if I add legend_position = "right" to my statebins_continuous() call, I get the following error:
Error in statebins_continuous... 'legend_position' must be either blank, 'none', 'top' or 'bottom'
Background: I'm working on a shiny app that visualises US House and Senate voting patterns (with two types of scores, so four combinations). Currently I use the highcharter
package however I want to switch to statebins
- it looks really neat! Highcharter also takes forever to load every time a setting is changed - I'm hoping statebins would be faster (although not yet tested).
Request: Would it be possible to show more than one variable value in a single bin (w/o using faceting)? I really like the new facet functionality, but I also don't want to display 2x2 US maps to the user on a single page. I couldn't really find a working example (which might be telling), so I am attaching some hastily done photoshop'd possibilities:
Not sure about the feasibility of any of these, but looking forward to your response! Cheers.
/Gokhan
I hesitate to ask this, given how quickly you responded (over the weekend!) to my request via twitter, but here goes--is it much work to allow statebins to accept a facet_wrap
or facet_grid
argument?
Not being in the USA, but being very interested in the way this expresses data, would it be possible (read easy) to make this more general so I could have a data frame with a column variable equivalent to whree you have the US states initials (e.g. maybe Australian suburbs, geographic regions, etc) and produce the similar coloured grid result (i am thinking of e.g. population, average wages, number living alone, etc)?
Thanks
Dan Raymond
Are there any plans to support plotting for DC and Puerto Rico?
Thanks
Following up from Twitter; how to get rid of the white background at the edges that resists all my attempts at removing them?
library(shinydashboard)
library(ggplot2)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(fluidPage(fluidRow(
plotOutput("statebins1")),
fluidRow(
plotOutput("statebins2"))
))
)
server <- function(input, output) {
output$statebins1 <- renderPlot({
us.data <- data.frame(cbind(state.abb, state.area), stringsAsFactors = FALSE)
us.data$state.area <- as.numeric(us.data$state.area)
statebins::statebins(state_data = us.data, state_col = "state.abb", value_col = "state.area")
})
output$statebins2 <- renderPlot({
statebins::statebins(state_data = us.data, state_col = "state.abb", value_col = "state.area") +
theme(axis.text.x = element_blank(), axis.text.y = element_blank(), axis.ticks =
element_blank(), panel.grid.minor = element_blank(), panel.grid.major = element_blank(),
plot.background = element_rect(fill = "#ecf0f5"))
})
}
shinyApp(ui, server)
Hi there,
I'm trying to recreate the CDC State FluView map you created using statebins() in your cdcfluview GitHub repo example code (I've made no significant changes). I get the following warning:
Warning: show_guide
has been deprecated. Please use show.legend
instead.
Looking at the statebins.R file, I see that there are 3 lines where show_guide=FALSE is specified. I imagine that replacing this with show.legend=FALSE will eliminate this warning.
Hi, is it possible to let the map show not only state name, but also the values? Maybe a bigger font for state and then a smaller text for the value?
Thanks in advance.
How hard would it be to create statebins as an sp object with reasonable lat and long values? I'm thinking about modifying geom_map()
so it can take sp
objects as input, and switching between actual state borders and binned border would be interesting.
(That would also make it easy to generalise statebins to other shapes)
I'm following the example on https://rud.is/b/2017/11/18/statebins-reimagined/
When I run the code
statebins(USArrests, value_col="Assault", name = "Assault") +
theme_statebins(legend_position="right")
I get the error below
Error in theme_bw(base_family = base_family, base_size = base_size, base_line_size = base_line_size, :
unused arguments (base_line_size = base_line_size, base_rect_size = base_rect_size)
devtools::session_info()
Session info ------------------------------------------------------------------------
setting value
version R version 3.3.3 (2017-03-06)
system x86_64, mingw32
ui RStudio (1.1.383)
language (EN)
collate English_United States.1252
tz America/New_York
date 2017-11-19
Packages ----------------------------------------------------------------------------
package * version date source
colorspace 1.3-2 2016-12-14 CRAN (R 3.3.2)
devtools 1.12.0 2016-06-24 CRAN (R 3.3.2)
digest 0.6.10 2016-08-02 CRAN (R 3.3.2)
ggplot2 2.2.1 2016-12-30 CRAN (R 3.3.2)
gtable 0.2.0 2016-02-26 CRAN (R 3.3.1)
labeling 0.3 2014-08-23 CRAN (R 3.3.0)
lazyeval 0.2.0 2016-06-12 CRAN (R 3.3.2)
memoise 1.0.0 2016-01-29 CRAN (R 3.3.2)
munsell 0.4.3 2016-02-13 CRAN (R 3.3.1)
plyr 1.8.4 2016-06-08 CRAN (R 3.3.1)
RColorBrewer 1.1-2 2014-12-07 CRAN (R 3.3.0)
Rcpp 0.12.8 2016-11-17 CRAN (R 3.3.2)
rlang 0.1.4 2017-11-05 CRAN (R 3.3.3)
scales 0.5.0 2017-08-24 CRAN (R 3.3.3)
statebins * 1.3.0 2017-11-19 Github (1d93f7a)
tibble 1.3.4 2017-08-22 CRAN (R 3.3.3)
withr 1.0.2 2016-06-20 CRAN (R 3.3.2)
yaml 2.1.14 2016-11-12 CRAN (R 3.3.3)
I'd love to be able to use geom_rrect()
, but (as a new package developer) I'm really struggling to make use of it in a way that would be allowed on CRAN. Is it possible to make it exportable, please? Thanks so much!
If I try adding a plot title to the help example:
data(USArrests)
USArrests$state <- rownames(USArrests)
statebins(USArrests, value_col="Assault", text_color="black", font_size=3,
plot_title = "1973 Assault arrests",
legend_title = "Assault", legend_position="bottom")
I get no plot, no error, and the following output in the console:
TableGrob (2 x 1) "arrange": 2 grobs
z cells name grob
1 (1-1,1-1) arrange gtable[layout]
sub 2 (2-2,1-1) arrange text[GRID.text.716]
Is anyone else having this problem, or maybe something with my setup?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.