Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abstracting to facets #10

Open
thomasjwood opened this issue Nov 20, 2017 · 15 comments
Open

abstracting to facets #10

thomasjwood opened this issue Nov 20, 2017 · 15 comments
Assignees

Comments

@thomasjwood
Copy link

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?

@hrbrmstr hrbrmstr self-assigned this Nov 20, 2017
@hrbrmstr
Copy link
Owner

they aren't technically geom's … but … since I added in a geom for the rounded corners, it got me thinking that adding a a "statebins" Stat and Geom wld not be a bad idea.

I'll keep you posted as it's def a gd idea.

@hrbrmstr
Copy link
Owner

So, something like…

library(statebins)
library(cdcfluview)
library(hrbrthemes)
library(tidyverse)

flu <- ili_weekly_activity_indicators(2017)

ggplot(flu, aes(state=statename, fill=activity_level)) +
  geom_statebins() +
  coord_equal() +
  viridis::scale_fill_viridis(
    name = "ILI Activity Level  ", limits=c(0,10), breaks=0:10, option = "magma", direction = -1
  ) +
  facet_wrap(~weekend) +
  labs(title="2017-18 Flu Season ILI Activity Level") +
  theme_statebins(base_family = font_ps) +
  theme(plot.title=element_text(size=16, hjust=0)) +
  theme(plot.margin = margin(30,30,30,30))

image

?

@thomasjwood
Copy link
Author

thomasjwood commented Nov 20, 2017 via email

@hrbrmstr
Copy link
Owner

Thx. I literally (as I hit ENTER) just pushed this up so if you get a chance to kick the tyres any and all feedback wld be greatly appreciated. Was a quick but pretty thorough hack this AM :-)

@thomasjwood
Copy link
Author

thomasjwood commented Nov 20, 2017 via email

@thomasjwood
Copy link
Author

When I attempt to replicate the flu facets above, with

ggplot(flu, aes(state=statename, fill=activity_level)) +
  geom_statebins() +
  coord_equal() +
  viridis::scale_fill_viridis(
name = "ILI Activity Level  ", limits=c(0,10), breaks=0:10, option = "magma", direction = -1) +
  facet_wrap(~weekend) +
  labs(title="2017-18 Flu Season ILI Activity Level") +
  theme_statebins(base_family = font_ps) +
  theme(plot.title=element_text(size=16, hjust=0)) +
  theme(plot.margin = margin(30,30,30,30))

I get

Error in gzfile(file, mode) : cannot open the connection
In addition: Warning message:
In gzfile(file, mode) :
  cannot open compressed file '/tmp/setupdata.rds', probable reason 'No such file or directory'

@hrbrmstr
Copy link
Owner

hrm. let me work up an example that doesn't depend on cdcfluview

@hrbrmstr
Copy link
Owner

give

library(tidyverse)

rownames_to_column(USArrests, "state") %>% 
  tbl_df() %>% 
  gather(crime, value, -state) %>% 
  ggplot(aes(state=state, fill=value)) +
  geom_statebins() +
  facet_wrap(~crime) +
  coord_equal() +
  labs(title="ggCrime") +
  scale_fill_distiller(palette="Reds") +
  theme_statebins()

a go

@thomasjwood
Copy link
Author

same error message:

Error in gzfile(file, mode) : cannot open the connection
In addition: Warning message:
In gzfile(file, mode) :
  cannot open compressed file '/tmp/setupdata.rds', probable reason 'No such file or directory'

and just because I'm a klutz, the data prep part on USArrests works ok:

rownames_to_column(USArrests, "state") %>% 
   tbl_df() %>% 
   gather(crime, value, -state) %>% 
# A tibble: 2 x 3
    state  crime value
    <chr>  <chr> <dbl>
1 Alabama Murder  13.2
2  Alaska Murder  10.0

@hrbrmstr
Copy link
Owner

hrbrmstr commented Nov 20, 2017 via email

@haroldgil
Copy link

I'm also getting the same error ('/tmp/setupdata.rds': no such file or directory). The first time may have been because of a bad install. After reinstalling, I didn't get any warnings or error messages and the install ended with SUCCESS, but I'm still getting the same error.

@thomasjwood
Copy link
Author

same, a reinstall still results

Error in gzfile(file, mode) : cannot open the connection
In addition: Warning message:
In gzfile(file, mode) :
  cannot open compressed file '/tmp/setupdata.rds', probable reason 'No such file or directory'

@haroldgil
Copy link

haroldgil commented Dec 5, 2017

In both the cdcfluview and USArrests examples, the error (cannot open compressed file '/tmp/setupdata.rds') is triggered at the "+ geom_statebins()" step.

@haroldgil
Copy link

I've been looking at the line saveRDS(xdat, "/tmp/setupdata.rds") in geom-statebins.R. I noticed that my local statebins package folder doesn't have a folder named "tmp". Creating it manually doesn't get rid of the error. So I'm wondering if one of the issues has to do with the first forward slash in the target directory.

Example:
x <- "abc"
saveRDS(x, "/tmp/setupdata.rds") does not work for me, but
saveRDS(x, "tmp/setupdata.rds") does (after manually creating a folder 'tmp' in my working directory). Maybe this has to do with me being on a Windows machine.

@haroldgil
Copy link

I forked the statebins repo, made the substitution described above [to saveRDS(x, "tmp/setupdata.rds") ], installed the edited version of the package, and now both code examples (flu and USArrests) discussed above work for me. I'll submit a Pull Request with the change in a minute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants