I thought this would be easy ... but couldn't find a solution. I am trying to generate a ggplot2 in R with correlation between col1 and col2, and size of the dot with col3, and shape with col4. col3 and col4 has NA/missing values. When running the code below, ggplot2 removes the rows without a matching col3 and/or col4, however, I want to keep these and color code. Output below
Example dataframe:
Warning: Removed 3 rows containing missing values (geom_point).
- I tried to create another geom_point with is.na(df$col3 | df$col4) but that wouldn't work.
- tried adding na.rm=FALSE in
geom_point(aes(size=df$col3, col=df$col4), na.rm=FALSE)
- tried
scale_size(range = c(0.25,4), na.value = 0) #to give a 0 value to the na.value (although would rather not)
But, I ended with "Ignoring unknown aesthetics: na.rm" for #2 and #3, and #1 gave an error. Also, that doesn't fix the issue that col4 shapes are being removed too
ggplot(df, aes(x=df$col1, y=df$col2)) +
geom_point(aes(size=df$col3, col=df$col4), na.rm=FALSE) +
theme_classic() +
scale_size(range = c(0.25,4))
+-------------+-------------+-------------+----------+
| col1 | col2 | col3 | col4 |
+-------------+-------------+-------------+----------+
| 0.254393811 | 0.124242905 | NA | NA |
| 0.28223149 | 0.148601748 | 0.236953099 | CD8CTL |
| 0.205945835 | 0.074541695 | NA | NA |
| 0.199758631 | 0.103369485 | NA | CD8Mem |
| 0.2798128 | 0.109511863 | 0.396113132 | CD8STAT1 |
| 0.254616042 | 0.059495241 | 0.479590212 | CD8CTL |
| 0.197929395 | 0.10993698 | 0.272611442 | CD8CTL |
| 0.294888359 | 0.12319682 | 0.16069263 | CD8CTL |
| 0.191407446 | 0.086443936 | 0.36596486 | CD8CTL |
| 0.267533392 | 0.11240525 | 0.344659516 | CD8CTL |
+-------------+-------------+-------------+----------+