1

This is the first time I post a question here, so I hope it works fine!

I'm in the process of building a donut chart. Thanks to the help of several websites, I managed to plot it. However, there is an issue that I don't know how to solve... R asked me to use discrete values. Hence I used factor(variable) to make it work, but now it pops up in the legend and I want it to appear without that info (just HG, no factor(HG) and no a). Please find below the code used and attached a picture of how the graph looks like.

Any idea on how to get rid of it would be appreciated.

ggplot(test, aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill=factor(HG))) +
  geom_rect() +
  geom_text(x=4.2, aes(y=labelPosition, label=label, color=factor(HG)), size=4) + 
  scale_fill_manual(values=colores) +
  scale_color_manual(values=colores2) +
  coord_polar(theta="y") +
  xlim(c(1.5, 4)) +
  theme_void() +
  theme(legend.position = "right") +
  ggtitle('TSI per HG') +
  theme(plot.title = element_text(hjust = 0.5))*

enter image description here

zx8754
  • 52,746
  • 12
  • 114
  • 209
  • No data to test your code, I am guess you don't need color argument in geom_text. – zx8754 Nov 18 '19 at 17:09
  • Hi there, many thanks for your help. You are right about geom_text, with that the a's are gone. There's still the factor in the legend's title (factor(HG)), which is used in aes(fill). I'm trying to find how to edit the question to upload the data... – Sofía M. Alía Nov 18 '19 at 17:17
  • Either change your data before using it within ggplot, or use custom name for the plot: something like `scale_fill_discrete(name = "HG")`, see https://stackoverflow.com/q/14622421/680068 – zx8754 Nov 18 '19 at 17:20
  • 1
    You can try `labs(color = "HG")` – dc37 Nov 18 '19 at 17:24
  • 1
    It works adding name = 'HG' in scale_fill_manual. Thanks a lot for the help, zx8754! – Sofía M. Alía Nov 18 '19 at 17:25

0 Answers0