Category "ggplot2"

How to connect grouped points in ggplot within groups?

I have a dataset with two groups - Experimental and Control. Each participant contributes two responses per group, which represent different learning styles. Th

Ordered bar plot with multiple groupings

Example data are here I am struggling to create an ordered and grouped bar plot. Any assistance appreciated. I have found two similar questions that essentially

ggplot2, arrange multiple plots, all the same size, no gaps in between

I would like to arrange multiple plots into one figure, without any gaps between the plot area, and all plots being exactly the same size (see image below for a

Scatterplot comparing two variables with ggplot and tidy data

With untidy data, running a scatterplot comparing two variables is trivial in either base R or ggplot2. For example, here is a sample scatterplot from R for Dat

jitter according to density

i want to create a combination of violin- and dot-plot with ggplot. The idea is to shift the dots to the left and right if necessary, to avoid overlap. I know t

How to use na.omit with ggplot

The image shows the database, it starts with day 0 and ends with day 14. In between these, there are empty values for what I am plotting. I am unable to correc

ggplot with overlapping X axis label

I have a ggplot which looks like this. p2=ggplot(data=data1, aes(x=ID, y = value)) + geom_line(group=1,color='steelblue', size=2) + facet_wrap(~variable)+t

R ggplot2 Bar Chart with Round Corners on Top of Bar

I would like to create a ggplot2 bar chart with round corners at the top of the bars. Consider the following example data: data <- data.frame(x = letters[1:

How does ggplot2 split groups using cut_number if you have a small number of data points?

I am wondering about the "behind-the-scenes functionality of ggplot2 and cut_number. I have some pretty complex data that has many subsets of data with a relati

Is there a way to add the bin range label into the tooltip for a histogram using ggplotly in R?

library(tidyverse) library(ggplot2) library(plotly) data(mpg) ggplotly( mpg %>% ggplot(aes(x=hwy)) + geom_histogram(), tooltip = ("all")) When you

Why am I not getting high-resolution with ggsave()?

I'm trying to get 300 dpi images with ggsave, and am only getting the default 72 dpi. Here's an example of the code I'm using: library(tidyverse) x <- rnorm(

ggplot2 png file without background

Since a few months, ggplot2 started to save png files with a transparent background. The code output in Rstudio and when saved as pdf looks great. It happens ma

Extend x-axis with dates

I wish to use ggrepel to add labels to the ends of the lines of a ggplot. To do that, I need to make space for the labels. To do that, I use scale_x_continuous

ggplot2 legend items in a single horizontal row

It seems that the code I wrote and tested last week has now suddenly decided to change the output even though nothing in the code or the version of R or Rstudio

How to adjust facet size manually

I have a faceted plot with very diverse data. So some facets have only 1 x value, but some others have 13 x values. I know there is the parameter space='free' w

plotting geom_text() with free scale facet_wrap

I would like to plot geom_text() in a facet_wrap with scale = free. I tried to use geom_blank() or, set each height on each graph, but it was not successful. Wo

Density plot based on time of the day

I've the following dataset: https://app.box.com/s/au58xaw60r1hyeek5cua6q20byumgvmj I want to create a density plot based on the time of the day. Here is what

How to connect across multiple consecutive missing data values using geom_line?

I have a similar problem to Q: Connecting across missing values with geom_line, but found the answers provided only connect the lines when there is one missing

Stripping mapping such as colour and line type from an existing ggplot2 object to re-do it

Within a Shiny application, I would like to provide users the option to select a regression method and then show the fit on their data on an existing ggplot2 gr

Overlaying jittered points on boxplot conditioned by a factor using ggplot2

I am making a boxplot conditioned by a factor similar to this example: p <- ggplot(mtcars, aes(factor(cyl), mpg)) p + geom_boxplot(aes(fill = factor(am)))