Relative Content

Tag Archive for ggplot2

Getting a ggplot error I have never encountered before

libpng warning: Image height is zero in IHDR
libpng error: Invalid IHDR data
Error in grid.Call.graphics(C_path, x$x, x$y, index, switch(x$rule, winding = 1L, :
non-finite x or y in graphics path
In addition: Warning messages:
1: In grid.newpage() : agg could not write to the given file
2: Removed 4 rows containing non-finite outside the scale range (stat_density2d_filled()).

ggplot: Using commas in data labels with no blank space

I am working on a chart in ggplot. Some of my numbers are large (1000+) so I want to use commas as a thousands separator to make numbers easier to read. The problem is that I can’t figure out how to do that without R adding extra space to the left of the number in the data label box. Below is the code I tried, and the picture to demonstrate the problem. Any solutions? Thanks in advance!

Assigning colours to categories ggplot scale_colour manual

I’m trying to use scale_colours_manual in ggplot just to set one colour and the rest be assigned just to the scheme provided. This is so if more categories appear once this is automated we won’t have to adjust the code. I’ve tried something like this:

ggplot legend override.aes for points containing no data

I’m trying to create swimmer plot with ggplot by following online resources because Power BI service does not support swimplot package but supports ggplot 3.3.3. The plot looks good, but the legend does not work as expected. An error occurs when using guides(color = guide_legend(override.aes =…)). I’m guessing it is because one of the columns (DaysCR) contains no data. Is it possible to show “CR” in the legend for DaysCR even if no data? Then maybe the override.aes would work.

Y-axis count incorrect in ggplot2 dotplot

I’m creating a dot plot using ggplot2 in R to visualize the distribution of Sepal.Length in the iris dataset. However, the y-axis shows values from 0 to 1 as if it’s a density plot, when I need it to show actual frequency counts. Additionally, I noticed that the upper part of the plot gets trimmed when resizing, as shown in the image below. How can I fix these issues?