Category "ggplot2"

How to add_trace to a plotly object created from ggplotly in R

I want to be able to add a new line/trace to a plotly object. This plotly object will be created from a ggplot object using ggplotly. I tried 1. creating the pl

Creating predicted vs observed confidence interval graph

Hello and thank you for you time and consideration, I'd like to recreate this graph with ggplot. The top blue dots are the predicted values from my fitted model

possible to have separate factor levels for each axis in one graph?

I'm trying to plot a Sankey diagram of financial flows between a source country and counterpart country. ggplot(dat_ggforce, aes(x=x, id=id, split = y, value=yv

Add unique horizontal line for levels in facet_grid

I want to add a unique horizontal line across each row of a set of facet grid boxplots. x<-c("species_X","species_X","species_X", "species_Y","species_Y",

Arranging bars in multi-panel Lollipop chart using ggplot2

I am trying to plot a multi-panel Lollipop chart using ggplot2 using the following code #Data df =structure(list(Indices = c("Time", "Z11", "Z51", "Z61", "Z161"

ggplot2 geom_point position= "dodges" doesn't match the error bar dodge

Im trying to figure out the best way to plot changes in water potential through summer comparing two factors, soil cover treatments and irrigation. I reached a

Fitting a line to the mean values of a multilevel variable using geom_smooth

I have this dataframe. I create a plot representing on the y-axis "value" and on the x-axis each of the levels of "Column_S", which contains levels from S1 to S

How can I add a legend for error bars in ggplot?

I have been trying to amend what I thought was a straightforward legend on my GGPlot for a day now and not making much progress (I have searched extensively on

How to look at differences between 2 columns in R

I just need to write some code that will look at the difference between the "est_age" and "known_age" columns in my data set. Then I need to know what percenta

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(