1

Simple concept, unexpectedly confusing. I have a graph like this:

enter image description here

What I want to do is to replace the letters with small images (paintings, actually; so one painting for 'a', another for 'b', and so on).

Relevant code:

mydata <- read.xlsx("C:/...", 1)
plotdata = mydata[1:22,1:2]

v1 = plotdata[1:22, 1]  # categorical labels which we can hopefully replace with images
v2 = plotdata[1:22, 2]

distance_plot <- ggplot(plotdata, aes(x = v1, y = v2)) +
  geom_bar(stat = "identity", position = "dodge") + 
  xlab("") + ylab("") +
  theme(axis.ticks = element_blank(), axis.text.y = element_blank(), 
        panel.background = element_blank(), panel.grid.major.x = element_line(colour="grey"),
        axis.text.x = element_text(size = 20), legend.title=element_blank())

distance_plot + coord_polar(theta = "x")

Custom annotations don't work with polar coordinates. :( I've also tried just plotting one value (just as a proof of concept/to see if I could get it working) where the x value is an image, but this gave the following error:

Error: Aesthetics must be either length 1 or the same as the data (1): x

Bonus Q (but less important): how to insert each y-value either on top of the lines currently pointing to each label, or above each label, etc.?

I'm new to R as well so please take any less-than-optimal code with a grain of salt. :)

Iaroslav Domin
  • 2,698
  • 10
  • 19
  • Seems one of the only ways to do this that will work would be [this question's answer](https://stackoverflow.com/questions/34496000/trying-to-add-an-image-to-a-polar-plot-gives-error-annotation-custom-only-work/34507509). The trouble here is that grobs are drawn along x and y dimensions, where it doesn't make sense in the curved polar coordinate system. It means the only option seems to be manual placement of each image. Definitely not ideal, but you can get a result that works this way... just really suboptimal. – chemdork123 Jul 31 '20 at 12:45
  • I didn't expect it to work, but it did! Super hacky though. Thanks :) – neverreally Aug 04 '20 at 12:28
  • Yeah. It's much easier if you can represent without the polar coordinates. After all, you're drawing non-curved things on a curved coordinate system. Not to mention, the polar coordinate makes things really difficult to judge across the center. Is H or T in the plot you show bigger? Easy to tell without the polar coordinates, but really tough since they are across. – chemdork123 Aug 04 '20 at 12:40

0 Answers0