ggplot2: separate color scale per facet

前端 未结 2 1255
借酒劲吻你
借酒劲吻你 2020-12-29 05:24

Intuitively I\'m looking for something like: facet_(scales=\"free_color\")

I do something like

p <- ggplot(mpg, aes(year, displ, colo         


        
相关标签:
2条回答
  • 2020-12-29 05:45

    I'm not sure that this is an available option when you're colouring by a factor. However, a quick way to produce the individual plots would be something like this:

    d_ply(mpg, .(manufacturer), function(df) {
    jpeg(paste(df$manufacturer[[1]], ".jpeg", sep=""))
    plots <- ggplot(df, aes(year, displ, color=factor(model))) + geom_jitter()
    print(plots)
    dev.off()
    })
    

    Related Answers: Different legends and fill colours for facetted ggplot?

    0 讨论(0)
  • 2020-12-29 06:01

    I think you simply want to color by class, where each manufacturer makes several models, each only one or two per class:

    p <- ggplot(mpg, aes(year, displ, color=class)) + facet_wrap(~ manufacturer)
    p + geom_jitter()
    

    alt text

    0 讨论(0)
提交回复
热议问题