Repeat values to multiple plots when faceting

后端 未结 1 1044
慢半拍i
慢半拍i 2021-01-24 06:30

I\'ve a data.frame that looks like this:

> foo
        class      type    (0,10]    (10,20]    (20,30]    (30,40]
    1       A             0.6              


        
相关标签:
1条回答
  • 2021-01-24 06:51

    You will have to do the data duplication due to ggplot's philosophy: Each item in the plot represents exactly one data point. So if you want to have the NA data in two facets, you need to create two data points for each original data item.

    If you want to avoid explicitly creating temporary data just for plotting, you can create a function that will do the data duplication for you. Something along the following lines:

    distribute.na.type <- function(dat) {
      rbind(
        transform(subset(dat, type %in% c(1, NA)), type=1),
        transform(subset(dat, type %in% c(2, NA)), type=2)
      )
    }
    

    The above example is untested and not very generic, but with a little bit of luck it'll just work. Use it like this: distribute.na.type(melt(...)).

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