Save plot without showing it at all

Is it possible to save a plot without displaying it at all ? I made a little ggplot hack to be able to copy graphs to powerpoint easily, it copies the plot to the clipboard, but one can see the device window open and close fast, it's a bit awkward, ...
more »

2017-11-10 12:11 (2) Answers

add text to ggplot in loop

In every cycle of a loop I create a ggplot object and I want to add text to the plot according to the cycle. Here is my code: gp <- list() for(k in 1:3) { gp[[k]] <- ggplot() + geom_text(aes(x = 2, y = 1, label=k), colour = "#1874CD") }...
more »

2017-11-08 07:11 (1) Answers

R barplot beside and stacked

I try to create a barplot, that uses besides and stacked at the same time. I have something that is similar to what I want with facet: tmp <- morley tmp$loc <- paste("No", tmp$Run %/% 2, sep="") tmp$group <- as.logical(tmp$Run %% 2) tmp$y...
more »

2017-11-07 17:11 (1) Answers

Fix ggplot panel width in RMarkdown doc

I'd like to align the width of the panel in some ggplots in an RMarkdown document. I can do it by moving the legend to the top or bottom, but that's not ideal. Is there a way to specify panel width with the legend to the right? --- output: html_docu...
more »

2017-10-30 22:10 (3) Answers

Proportion with ggplot geom_bar

What is the simplest way to do with ggplot the same as done here: Do I need call prop.table or maybe there is a simplier way? REPRODUCTABLE EXAMPLE: x <- c("good", "good", "bad", "bad", "bad", "bad", "perfect", "perfect", "perfect") y <- c...
more »

2017-10-28 00:10 (2) Answers

Split geom_point points along x axis by group

This is driving me up the wall, and I'm sure I am missing something simple. Any help would be appreciated. I want the red and blue points to be separated, with each set over the corresponding boxplot as in second image, but with a numeric x axis a...
more »

2017-10-27 21:10 (3) Answers

ggplot2: Adding a geom without affecting limits

I would like to add additional geoms to a ggplot density plot, but without changing the displayed limits of the data and without having to compute the desired limits by custom code. To give an example: set.seed(12345) N = 1000 d = data.frame(measur...
more »

2017-10-24 12:10 (2) Answers

ggplotly - mismatching when using color aesthetics

I'm using ggplotly to convert a ggplot object to interactive plotly. The problem I'm encountering is when the ggplot object is using an associated color aesthetic. For example, using the following dummy example: library(ggplot2) library(plotly) da...
more »

2017-10-16 12:10 (0) Answers

R, rotating one ggplot within facet_wrap?

I'm having a ggplot2 facet_wrap based upon on factor with two levels. To make them easier comparable, I would like to reverse the y-axis of one of them, e.g. by using scale_y_reverse. But I haven't found a way to apply it to only one of plots? Is the...
more »

2017-10-15 22:10 (0) Answers

Nodes not respecting facetting in ggraph/igraph

I am having a little trouble understanding the difference between ggplot2 and ggraph with respect to facetting. Consider the following data: library(igraph) library(ggraph) library(ggplot2) df <- structure(list(x = c("H001", "H024", "H090", "H0...
more »

2017-10-12 23:10 (2) Answers

ggplot2: geom_bar, computing facet-wise percentage

I would like to use the geo_bar with facets, obtaining percentage instead of absolute counts, but percentage should be relative to each facet, not relative to the overall count. This has been discussed a lot (example), suggesting to use geom_bar(ae...
more »

2017-10-06 00:10 (1) Answers

Hierarchically faceting a ggplot

I have experimental data that I want to plot using ggplot's facet_grid. The experiment collected measurements from two species, three conditions, in 6 batches: species <- c("spcies1","species2") conditions <- c("cond1","cond2","cond3") batche...
more »

2017-09-29 22:09 (0) Answers