Category "ggplot2"

Ggplot2 rearranges wrongly the bars in a plot bar when value is null

Given the following data, I compose a data frame with a factor and a numeric column. X2 <- c(4,4,3,5,4,4,2,3,4,3,5,5,4,3,3,4,2,3,3,4,3,5,3,3,4,4,3,3,5,4,5,4,

How to split negative and positive bars by zero line in barplot?

My data have 2 numerical columns (positive and negative values) and 2 categorical variables. Now I want to plot negative and positive bars on same line, instead

Divide Legend by multiple groups

In am looking a solution to a different representation of the legend to the example given here: https://rpubs.com/ageek/ggplot-adv-part2 The code below gives th

Converting character to date turning all dates to NA & x-axis of ggplot not in chronological order [duplicate]

I am using an online ONS dataset of inflation and trying to chart it, but when plotting it with ggplot the x-axis is not in chronological orde

How can I plot the intercept and coefficient of my LMM with 95% confidence interval over spagetti plots in R?

To visualize the results of my linear mixed model (LMM) I would like to plot spagetti plots that track the change in volume1 over time for all participants. I w

app$vspace error in building phylogenetic tree in R

I am working with phylogenetic trees. Import the phylogenetic tree file with ggtree::read.tree and get the information with readxl::read_xlsx. I want to visuali

Facet title alignment using facet_wrap() in ggplot2?

I'm making a plot involving facets, and I am trying to fix the alignment of the facet/strip title. Right now it seems to left align to the panel, which places i

How to apply slope plot R code to another data

I have dataframe which represents sales by model within 2 different years. 'change' column stands for absolute change by models from 2020 to 2021 while 'chng.pe

Overlay KDE and filled histogram with ggplot2 (R)

I'm quite new in R and I'm struggling overlaying a filled histogram divided in 6 classes and a KDE based on the whole distribution (not the individual distribut

Is there a way to use different y-values per facet in R?

I'm relatively new to R and I'm struggling to figure out a way to get a set of plots with different y values. Below is a simplified version of the dataset I'm w

cat_plot showing same confidence intervals for all data points (interactions package in r)

I am using the cat_plot function from the [interactions]https://interactions.jacob-long.com/reference/cat_plot.html package to plot a 2-way interaction between

R plotting code behaves differently for CSVs containing different data formatted the same way

I have two CSVs for experimental data measuring the effects of a two values of a single variable. Basically the code is the same except for the name of the data

Stacked histograms with ggridges package in R

The following code produces histograms that overlap. How can I modify this code to make the histograms stack on top of each other? library(tidyverse) library(gg

How to adjust the ratio of my x axis in my line graph in r?

I am creating a line graph in R using ggplot2. So far the graph is looking fine (I am relatively new to all this), but I have run into an issue trying to adjust

In R - How do I plot the data from the row where the date=='"2020 Q1' to the last row of the dataframe?

example of the data: Date Inflation 2020 Q1 2 2020 Q2 2.1 2020 Q3 2 2020 Q4 2.1 I am using ggplot ggplot(CPI,aes(x=date,y=inflation,group=1))+geom_line() but

How to change tickmode for all subplots of facet_grid

I want to change the tickmode of all xaxis/yaxis in all subplots to "auto" but the number of subplots changes. I tried the following code. It works for the firs

R ggplot with 2 y-axes at different scales

The following is df_sales df_sales <- structure(list(Year_of_Release = c(2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013,

Lay out multiple ggplot graphs on a page

I generate a list of ggplot objects inside a loop as follows: myPlots = list() for(i in 1:length(maturities)){ myPlots[[i]] <- ggplot(deltaIR.df, aes(samp

GGPlot, fill by proportion with a geom_col()

I am trying to make each column fill by the proportion of each type of medal (Bronze, Silver, Gold) in relation to the Medal_sum for each country. Olympic_overa

How to one barplot into two within one picture?

This is my code: p14 <- ggplot(plot14, aes(x = Harvest, y = Percentage, fill = factor(Plant, level = orderplants)))+ geom_col(show.legend = FALSE)+ geom_