Code Monkey home page Code Monkey logo

Comments (7)

jrnold avatar jrnold commented on May 16, 2024

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.

from ggthemes.

jankatins avatar jankatins commented on May 16, 2024

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?!

from ggthemes.

jrnold avatar jrnold commented on May 16, 2024

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.

from ggthemes.

jankatins avatar jankatins commented on May 16, 2024

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 :-)

from ggthemes.

jrnold avatar jrnold commented on May 16, 2024

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.

from ggthemes.

cboettig avatar cboettig commented on May 16, 2024

👍 this would be great

from ggthemes.

jrnold avatar jrnold commented on May 16, 2024

Implemented in the xkcd package.

from ggthemes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.