0

I want to add leading lines to all the slices in my ggplot Pie Chart.

The second answer on this thread has them, but IDK what was added to reproduce the line, ggplot pie chart labeling

I've tried to copy and paste exactly what's in the line part of this answer, but I get some messed up lines: Controlling ticks and odd text in a pie chart generated from a factor variable in ggplot2

Here's my messed up chart

lossmixchart <- ggplot(currentLoss, aes(x="", y = currentLoss$Incurred, fill = 
                Branch)) + 
  geom_bar(width = 1, stat = "identity", colour = "black")+ 
  coord_polar("y", start = 0) + 
  scale_fill_manual(values = 
                c("British Columbia" = "royalblue3", "Alberta" = "red", 
                "Saskatchewan" = "green4", "Manitoba" = "gold", "Ontario" = 
                "turquoise", "New Brunswick"= "purple", "PEI" = "hotpink", 
                "Nova Scotia" = "orange")) +
  theme_void() + 
  ggtitle(paste0(
                "Incurred Loss Mix in Thousands ", 2019, ": " , currentProvince)
            ) + 
  geom_text_repel(mapping = aes(label = paste0(Branch, " \n $", 
                prettyNum(round(currentLoss$Incurred/1000), big.mark = ",")), x = 2), 
                position = position_stack(vjust = 0.5), segment.size =.7, size = 5, 
                show.legend = FALSE) + 
  theme(legend.position = "none", 
        plot.title = element_text(face = "bold", size = 20), 
        axis.title = element_text(size=20),
        axis.title.y = element_blank(),
        axis.title.x = element_blank())

 print(lossmixchart, floating = FALSE)  

If I add nudge_x = .3 after size, as some pages advise to try, I get this error:

Error: Specify either `position` or `nudge_x`/`nudge_y

TobiO
  • 1,335
  • 1
  • 9
  • 24
morg
  • 381
  • 2
  • 17
  • please add some example data, also please show, where exactly you add the `nudge_x` – TobiO Jul 23 '19 at 09:54
  • I think you should add `nudge_x` to the `geom_text_repel` as in the answer you're referring to. There you're already setting a position which might cause the error – TobiO Jul 23 '19 at 10:11
  • I already put it in geom_text_repel, after size like I said above, so it looks like this ```geom_text_repel(mapping = aes(label = paste0(Branch, " \n $", prettyNum(round(currentLoss$Incurred/1000), big.mark = ",")), x = 2), position = position_stack(vjust = 0.5), segment.size =.7, size = 5, nudge_x = .3, show.legend = FALSE)``` – morg Jul 23 '19 at 13:26
  • I see several issues with your plotting calls. Please provide some example data to work on. What do you actually want to achieve with `nudge_x`? Move the labels more outward? – TobiO Jul 23 '19 at 14:06
  • https://docs.google.com/spreadsheets/d/1IxE0odVhLn41oU_-ECIOBdWiUXVDE_IvEn_MW2Lr5Mo/edit?usp=sharing here's some data, Overall I want to add leading lines, however I also don't want my labels to overlap with the chart OR other labels, right now they do both sometimes – morg Jul 23 '19 at 14:15
  • I have a loop right now that goes through the above data and filters based on each of the provinces for years (for this, all provinces is fine because I also have a chart that way) so at any given time, IDK how the labels for each loop will show up – morg Jul 23 '19 at 14:16

0 Answers0