0

I've produced a circular plot using the data below:

Var1     Var2 Freq
1  not specified     bath    4
2  not specified  current   20
3          MODIS      DSL    1
4  not specified      DSL    1
5       SeaWiFS       DSL    1
6  not specified    front    2
7       SeaWiFS     front    2
8  not specified      img    1
9  not specified       O2    1
10         AVHRR ocn prod    3
11    IRS-P4 OCM ocn prod    1
12         MERIS ocn prod    1
13         MODIS ocn prod   17
14 not specified ocn prod   12
15           OCI ocn prod    1
16      SeaWiFS  ocn prod   20
17         MODIS salinity    1
18 not specified salinity    1
19 not specified      SSH   35
20        AMSR-E      SST    4
21         AVHRR      SST   38
22          CZCS      SST    1
23        Imager      SST    3
24         MODIS      SST   18
25 not specified      SST   23
26      SeaWiFS       SST    1
27         AVHRR   vessel    1
28 not specified   vessel    1
29 not specified     wind    3
30      SeaWinds     wind    1

Using this code;

circ.plot = ggplot(var.sens, aes(x=as.factor(id), y=Freq, fill=Var2, label=Var1)) +       
  geom_bar(stat="identity", alpha=0.5) +
  geom_segment(data=grid_data, aes(x = end, y = 30, xend = start, yend = 30), 
               colour = "grey", alpha=1, size=0.3 , inherit.aes = FALSE ) +
  geom_segment(data=grid_data, aes(x = end, y = 20, xend = start, yend = 20), 
               colour = "grey", alpha=1, size=0.3 , inherit.aes = FALSE ) +
  geom_segment(data=grid_data, aes(x = end, y = 10, xend = start, yend = 10), 
               colour = "grey", alpha=1, size=0.3 , inherit.aes = FALSE ) +
  annotate("text", x = rep(max(var.sens$id),3), y = c(10, 20, 30), 
           label = c("10", "20", "30") , color="grey", size=3 , angle=0, 
           fontface = "bold", hjust = 1) +
  geom_bar(stat = "identity", alpha = 0.5) +
  ylim(-30,40) +
  theme_minimal() +
  theme(
    legend.position = "none",
    axis.text = element_blank(),
    axis.title = element_blank(),
    panel.grid = element_blank(),
    plot.margin = unit(rep(-1,4), "cm")) +
  coord_polar() +
  geom_text(data=label_data, aes(x=id, y=Freq+2, label=Var1, hjust=hjust),
            color="black", fontface="bold",alpha=0.6, size=2, 
            angle= label_data$angle, inherit.aes = FALSE ) +
  geom_segment(data=base_data, aes(x = start, y = -2, xend = end, yend = -2), 
               colour = "black", alpha=0.8, size=0.75 , inherit.aes = FALSE )  +
  geom_text(data=base_data, aes(x = title, y = -4, label=Var2), 
            hjust=c(1,1,1,1,1,1,0,0,0,0,0,0), 
            vjust=c(0,0,0,0,0,0,0,0,0,0,0,0),
            angle=c(90,70,40,20,0,-5,100,70,60,0,-40,-60),
            colour = "black", alpha=0.8, size=2, fontface="bold", 
            inherit.aes = FALSE)
circ.plot

This produces this circular plot enter image description here

However, the graphics are really grainy and the lines aren't crisp. The text seems wonky as well. This isn't like the examples from the code I made this from. Has anyone had an issue with the graphics from ggplot like this? And how do you solve them? Or is this just an issue with circular plots?

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
mikejwilliamson
  • 405
  • 1
  • 7
  • 17
  • 1
    For one thing, it seems like you have a lot of geoms that don't need to be repeated. Instead of hardcoding values, use data and map its variables onto aesthetics in your plots (I'm looking at the multiple `geom_segment`s with manually set y). Please try to pare the code down to just the essentials, including by using `aes` to reduce redundant geoms – camille Jul 12 '18 at 15:01
  • Can you please provide your data in a reproducible format? https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. Also, I'm not sure why one would want to use a graph like this instead of a much more readable, "regular" bar chart. Is there a specific reason for using this format? – Ben G Jul 12 '18 at 15:01
  • I don't know gglot, but I can tell you that these kinds of artifacts result from rounding control points (polygon corners, start and end of text baseline, etc) to the nearest pixel, when the features being drawn are small and the control points are only a few pixels apart. You probably need to draw this chart at a much higher resolution and then downsample/resize it smaller, or draw it originally with anti-aliasing if you can do that in a way that avoids rounding to the nearest full pixel. – Matt Timmermans Jul 13 '18 at 03:15
  • Thanks that seems to be the issue! Outputting the fie at higher resolution seems to solve the issue. Thanks! – mikejwilliamson Jul 16 '18 at 07:53
  • Thanks this seems to have solved the issue. It was just too low resolution. Saving the image as a higher resolution resolves this issue. Cheers – mikejwilliamson Jul 16 '18 at 07:55

0 Answers0