Closed jankatins closed 11 years ago
Thanks for sending me that link, I had missed that stackoverflow thread :-( The answer by dystroy was as good as you can do with ggplot. You can get the xkcd plot theme by using the following (after downloading Humor Sans and using the extrafont package as discussed in SO)
... + theme_tufte(ticks=FALSE) + theme(text=element_text(family="Humor Sans")
As for the jittered axis lines, the way that they are implemented in that post is the way to do it in ggplot. The only way to make it less hackish is to wrap that hack into a geom. This is why I had to implement Tufte's range frames as geom's rather than it being part of the theme.
Which actually means that I should be able to tweak some code in either geom_rangeframe or geom_rug, from which I adapted range frame, to allow for jittered axis lines. I'll give that a shot and I might either adapt geom_rangeframe or add a new axis line geom.
Should I file a bugreport at ggplot2 about the "none-themable" axis lines (both for xkcd style plots and your tufte one)?
It would be really cool if you could just do a + theme_xkcd()
and the plot would be changed without changing any geom_...()
. As far as I understood the hack, themes would also need the ability to set "jitter" for everything which draws a line?!
To the extent that I understand ggplot2 and the way it separates concerns, you will always need to mess with the geoms to get xkcd like plotting. The theme does not alter the behavior of the geoms; it only changes the look of background material for the plot. For example, the theme cannot alter the default color of geoms; this is why this package includes color scales with matching themes.
So the xkcd plots cannot be implemented just as a theme in the same way that to make an Economist plot requires both theme_economist() and color_scale_economist().
If you aren't aware of it, check out the function update_geom_defaults. If you do
update_geom_defaults("line", list(position="jitter"))
all future geom_line
lines will be jittered.
It should be possible, to write a function that sets these defaults for the geoms, and the theme, and then produces the plot. The question being how much work it is get enough generality that it adds value beyond just writing the code.
Sorry that I don't have anything more concrete right now. I'll keep thinking about this. I know that the separation between geoms and themes has been a complaint against ggplot. I am thinking that there should be a way to define geom themes which are a collection of geom defaults, and then a way to evaluate ggplot object so that it uses those defaults without changing the global defaults.
I would argue that "hand-drawn look" is a thing of themes and therefore there should be a way to affect that via themes:-)
I would also argue that a theme should be able to set default colors and default axis styling: ggplot has a default color scheme and axis style, so just because you want to have it look (consistently) different I have to add a ggplot call to every plot: I would like to do it once and be done with it :-)
I will ask upstream if this would be an idea worth implementing. Let's see what they say :-)
I agree; and I think there should be some way to bundle a theme with default values for geoms and a default scales. From a theoretical perspective, since color perception is not independent of the background color, scales are never independent of the theme. I know that Stata themes set values for both background elements and the default colors for the equivalent of geoms. There are some issues in actually implementing this, which i remember reading about in some threads (but I don't fell like looking up right now :-) ). One thing to be aware of, is that all the code for implementing geoms is being rewritten. Maybe it will be easier to implement this in the future.
Last night I was playing around with a couple of ways to create something like a theme for geoms. I might also add functions which combine themes and scales.
:+1: this would be great
See here: http://drunks-and-lampposts.com/2012/10/02/clegg-vs-pleb-an-xkcd-esque-chart/ and http://stackoverflow.com/questions/12675147/xkcd-style-graphs-in-r
It would be nice if the axis,
geom_line(...)
and similar calls could be "jittered" without using hacks like in the blog post :-) Not sure if that is possible with hadley/ggplot2...