Search code examples
rggplot2colorsggforce

Line color in ggforce::geom_arc_bar


Probably a simple one.

Is there a way to eliminate the bordering line in a ggforce::geom_arc_bar pie plot?

pie <- data.frame(
    state = c('eaten', 'eaten but said you didn\'t', 'cat took it', 
              'for tonight', 'will decompose slowly'),
    focus = c(0.2, 0, 0, 0, 0),
    start = c(0, 1, 2, 3, 4),
    end = c(1, 2, 3, 4, 2*pi),
    amount = c(4,3, 1, 1.5, 6),
    stringsAsFactors = FALSE
)
ggplot(pie) + 
    geom_arc_bar(aes(x0 = 0, y0 = 0, r0 = 0, r = 1, amount = amount, 
                     fill = state, explode = focus), stat = 'pie') + 
    scale_fill_brewer('', palette = 'Set1') +
    coord_fixed()

enter image description here

For example, in the plot above either eliminate the black border line or make its color the same as the fill color?

And another question, is it possible to eliminate the border line only from the perimeter of the pie? So only the demarkation of the slices stays?


Solution

  • ggplot uses two parameters in general for colours:

    col = 
    

    and

    fill = 
    

    You assigned fill (internal), but didnt deal with col (outline).

    the following should work, where I assign col=NA

    ggplot(pie) + 
      geom_arc_bar(aes(x0 = 0, y0 = 0, r0 = 0, r = 1, amount = amount, 
                       fill = state, explode = focus), col=NA,stat = 'pie') + 
      scale_fill_brewer('', palette = 'Set1') +
      coord_fixed()
    

    EDIT: So to answer the second quesiton - I really don't know if this is possible (I am not overly familiar with ggforce) In light of this, I ask forgiveness in advance of this very 'hacky' solution to your problem. But I felt it was better to offer something for others to improve on.

    To explain: keep hte original outline, but then plot a new outline the same colour as each segment using the geom_arc0 function"

    geom_arc0(aes(x0 = 0, y0 = 0, r = 1, start = start, end = end, 
                  colour = factor(state)), data = pie, ncp = 50)
    

    in context:

    ggplot(pie) + 
      geom_arc_bar(aes(x0 = 0, y0 = 0, r0 = 0, r = 1, amount = amount, 
                       fill = state, explode = focus), col="black",stat = 'pie') + 
      geom_arc0(aes(x0 = 0, y0 = 0, r = 1, start = start, end = end, 
                    colour = factor(state)), data = pie, ncp = 50)
      scale_fill_brewer('', palette = 'Set1') +
      coord_fixed()
    

    It may look a bit dodgy - if you increase the ncp parameter it adds more points to the outline (thus getting closer to a perfect circle) - i was limited to ncp=2000.

    Again apologies that it is so hacky.