Note that there are some explanatory texts on larger screens.

plurals
  1. POLetter partially disappearing when exporting text using CairoPNG
    primarykey
    data
    text
    <p>I'm trying to construct a chart using ggplot which I am then saving to PNG image using the Cairo package's CairoPNG function.</p> <p>The problem is that the resulting image file seems to be missing chunks of the letter J on the x axis. This is a bit of an issue when I'm using month name as the x axis label.</p> <p>This only seems to happen when the text size is set to a whole number (such as 12). If I set it to 11.5 or 12.5 then the letters display fine.</p> <p>So, I can fix it by altering the font size but it feels like a bit of a hack. Does anyone know why it's behaving like this?</p> <p><img src="https://i.stack.imgur.com/4h87e.png" alt="enter image description here"></p> <p>Code is as follows:</p> <pre><code>library("ggplot2") library("scales") library("Cairo") # Set chart values line.width = 1 font.size = 12 # Generate some random data start.date &lt;- as.Date("2011-07-01") x.month &lt;-seq.Date(start.date, by = "month", length.out = 24) end.date &lt;- max(x.month) x.value &lt;- rnorm(24,mean=50,sd=2) # Combine into dataframe x.data &lt;- data.frame( "Month" = x.month, "Value" = x.value ) # Build chart p &lt;- ggplot(data=x.data, aes(Month, Value)) + geom_line(size=line.width) p &lt;- p + theme_bw() p &lt;- p + ggtitle("Test Chart\n") p &lt;- p + scale_y_continuous(limits = c(40, 60)) p &lt;- p + scale_x_date(limits=c(start.date+20,end.date-20), breaks = "1 month",labels = date_format("%b-%y")) p &lt;- p + theme(axis.text.x=element_text(angle=90, hjust=1, vjust=0.5, size=font.size), axis.text.y=element_text(size=font.size), axis.title.x=element_blank(), axis.title.y=element_blank()) # Export chart CairoPNG("c:\\temp\\temp1.png", width=500, height = 250) p dev.off() </code></pre> <hr> <p><strong>Edit 1</strong> I tried the following code suggested by baptiste but the letters seem to come through fine:</p> <pre><code>CairoPNG("test.png"); grid::grid.text("The disappearing J"); dev.off() </code></pre> <p><img src="https://i.stack.imgur.com/JhksJ.png" alt="enter image description here"></p> <hr> <p><strong>Edit 2</strong></p> <p>Issue isolated courtesy of baptiste. It really doesn't seem to like rotating capital Js!</p> <pre><code>CairoPNG("c:\\temp\\test.png",width=60, height=300); grid::grid.text("Rejoicefully Juxtaposing Jelly with Jam\nabcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ", rot=90); dev.off() </code></pre> <p><img src="https://i.stack.imgur.com/WLHjj.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload