57,712 questions
-1
votes
0
answers
43
views
Error plotting global shapefile over the dateline in R [duplicate]
I am trying to plot a global dataset of seamounts (full shapefile data can be found here).
seamounts <- st_read("YessonEtAl2019-SeamountBases-V2.shp")
I want to plot it centred on the ...
0
votes
0
answers
103
views
Print out plot with unicode symbol to PDF
I am using a Unicode symbol in my plot. It looks fine in RStudio, but when I try to save them to PDF, it disappears. How one can keep the Unicode symbols in PDF?
library(ggplot2)
plot <- ggplot(...
-2
votes
2
answers
110
views
ggplot superscript in axis labels [duplicate]
I created a plot using ggplot in R. Below is a working example of my code. The problem is that the superscript in the axis labels is crammed together and the minus sign is halfway in the number. Why ...
0
votes
1
answer
94
views
Show all other groups in grey behind each panel [duplicate]
I have this dataframe (see the code below) and the following plot.
What I need is a plot like the mock-up attached (made in PowerPoint): In each facet panel, I want to show in light grey all the data ...
3
votes
2
answers
144
views
Add significant differences in brackets in a half-violin plot
I am trying to make a half-violin plot. I want to add the significant differences as brackets above the halves, with an asterisk indicating significance.
Because I want to group the data into two ...
1
vote
0
answers
32
views
Issue with using ggdist::stat_halfeye() to plot within ggplot in R. Is this a compatibility issue? [duplicate]
I recently updated both ggdist, tidybayes, and ggplot2 in R, and now some code that I had previously running is not longer working. Instead I get the error message:
in self$geom$use_defaults(data, ...
0
votes
0
answers
103
views
How to get both plots on the same scale
Image of two graphs combined together:
I am currently attempting to make a ggplot with a boxplot and a path plot on the same image, the path plot is supposed to intersect with the median areas of the ...
1
vote
2
answers
146
views
Customizing label format in facet nested plots with ggplot2
I am trying to create a series of plots using ggplot2 in R, and I want to customize the labels in the facet nested plots, particularly to include subscripts for the ICC labels. Below is my attempt, ...
-1
votes
0
answers
43
views
How can I combine the two legends of my plot so the corresponding symbol and colour of each specimen are combined into one legend? [duplicate]
I have made a plot of a principle component analysis using ggplot2 (geompoint) and I currently have two legends, one showing the pch shape of each point and one showing the colour of each point. I ...
3
votes
1
answer
71
views
Facet breaks either sjPlot or geom_point
I am trying to produce with faceted sjPlot lines, and geom_points. mtcars data supplied as an example.
fit <- lm(mpg ~ cyl * hp * am, data = mtcars)
I want to have slopes of mpg by hp for each cyl,...
3
votes
2
answers
85
views
Trying to plot every 4th label on the x-axis in ggplot2
I have this figure, and as you can see, the x-axis is labelled every 2nd year. Now, since it is visibly congested, I am trying to make it every 4th year, i.e. 1990, 1994, 1998 and so on. How do I go ...
0
votes
0
answers
89
views
Error bars not aligned to vertical gridlines
This is the code:
library(ggplot2)
mortality_incidence_data <- read.csv("Report Data Death.csv")
mortality_incidence_data$year <-
factor(mortality_incidence_data$year,levels = c(
&...
-2
votes
1
answer
72
views
R ggplot: force legend guide of separate geoms onto separate rows when using horizontal legend [duplicate]
I am creating a chart with two different geoms and would like to include them on separate rows (one row per geom) in a legend at the top of the chart. For example:
ggplot(data = iris) +
geom_point(...
0
votes
1
answer
66
views
if statement to check for the presence for a dplyr column name [closed]
I have written the following function where when I pass the argument color_col the plot should color each of the traces with a seperate color. In this instance its the weekend column which has 3 ...
3
votes
1
answer
77
views
how to use if statement with plot_layout( )
I would like to combine 3 plots(p1+p2+p3) together with conditional plot_layout() to p_all. However I could not get my if statement work. Could anyone guide me on this?
p3 is for sure exist, but p1|...
6
votes
2
answers
173
views
ggh4x how to stretch strip across layers
I'm working on a facet_nested_wrap plot (see image below) where I happen to have one of the aspect (CENT) having only one level, as opposed to two, as in the other (TELO).
Is there a way to increase ...
0
votes
0
answers
65
views
Visualising a partial correlation using ggpredict - is this a sound method?
I am trying to create scatter plots showing the partial effects of the significant variables from my linear mixed effects model. The model is examining the association between various behavioural ...
6
votes
2
answers
151
views
Removing outside border line in R map
I am working on highlighting groups of counties within Ohio and while I am happy with where I have ended up overall, I have one aesthetic issue I cannot seem to solve.
Goal: Map of Ohio with grouped ...
1
vote
1
answer
94
views
Alphabetical ordering of y-axis in complex ggplot2
I'm trying to make a line chart of the density of different species along a vegetation transect.
There are two transects (Transect A and Transect B), which I would like to plot separately.
"Cover&...
0
votes
1
answer
138
views
Creating a bar graph with categories derived from multiple columns
I have generated the following summary of means and SDs for two parameters, SAR and ER, for several multi-column categories:
structure(list(category = c("DIT GROUP\nCR 16.0005\nADB", "...
0
votes
1
answer
43
views
Adding geom_text in patchwork with shared y-axis and both positive and negative values
I have a patchwork plot consisting of a total of four plots. The procedure I’m asking about is mainly relevant for two of them, though I believe it can be applied to both. These two plots share a ...
0
votes
1
answer
97
views
Build forest plot for estimate comparison of multiple models using ggplot2. How to add text of CI?
I am trying to create a forest plot to compare estimates of different models.
Tho goal is to plot all the estimates of the same predictor for the different models so they are comparable.
For this I ...
0
votes
2
answers
84
views
Positioning of geom_text with negative stacked geom_bar
I have a ggplot2 plot with both positive and negative geom_bar values. For the geom_bar that shows the negative values, I’m having an issue where the position of geom_text is not displayed correctly. ...
2
votes
1
answer
97
views
Area with color gradient
I created this simple ggplot2 plot and would like to generate a vertical color gradient for the area between y = 0 and the respective values, possibly using geom_ribbon (?). However, I haven’t found ...
1
vote
1
answer
46
views
R geom_contour_filled date scale
I have 3D data that are all dates. I want to plot them with a contour. I have almost what I want with geom_contour_filled of package ggplot2 but I struggle to obtain a decent legend as dates (I'd like ...
3
votes
1
answer
70
views
How to use Times New Roman and italicization in equation in ggplot2?
I need all text in my graphs to be in Times New Roman. I also need the variables (R, P) generated in stat_poly_eq to be italicized. However, it seems that setting the font to Times New Roman ...
3
votes
1
answer
108
views
How to plot data like an animated ECG in R?
I have a 2 min data set sampled at 10 Hz that I want to plot like an ECG in R: I want to create a plot with a 30 s window, plot the first 30 s from left to right in real time, then after 30 s, the ...
1
vote
1
answer
110
views
stat_ellipse() in MCA plot does not cover jittered points / extends far beyond the data
I am creating a Multiple Correspondence Analysis (MCA) plot in R using FactoMineR, factoextra, and ggplot2. The goal is to add confidence ellipses around the archetype categories in the MCA space.
The ...
Advice
0
votes
5
replies
188
views
Drawing geometric diagrams in R, ggplot
To illustrate the ideas behind discriminant analysis, I created the image below containing a scatterplot with two groups and a plot of the densities of the scores, LD1 on the discriminant function.
...
2
votes
2
answers
106
views
Reorder stacked bar graph by value [duplicate]
What is the easiest-to-replicate way of reordering these bar graphs (
group1, group2) so that it is arranged in ascending order of col3 from bottom to top? I am looking for a solution that can be used ...
0
votes
1
answer
99
views
Confidence interval not covering the entire x axis [closed]
The confidence interval on my scatter plot doesn't cover the entire x axis, while the regression line fits the entire data set. The data that isn't covered by the c. interval doesn't have any missing ...
1
vote
1
answer
100
views
Error with stat_pointinterval() associated with aesthetics [closed]
I have previously used the stat_pointinterval() function from the R package tidybayes to make plots of the median and credible intervals around model parameters.
While re-running code today, none of ...
3
votes
1
answer
125
views
Creating a plot for residuals
I have following linear regression model:
library(nlme)
library(lattice)
data(Orthodont)
model = lm( distance ~ age * Sex, Orthodont)
lattice::bwplot(getGroups(Orthodont) ~ resid(model))
However, I ...
4
votes
2
answers
123
views
Forcing a slope on a loess smooth
I have a set of two variables measured over time:
data <- structure(list(
time = c(0, 30, 60, 90, 120, 150, 210, 270, 330, 1350, 1470, 1710),
var1 = c(0.963, 0.942, 0.921, 0.933, 0.868, 0.727, 0....
1
vote
1
answer
84
views
Cropped polygon sf not filling plot area after being projected
I am running code that I previously used to create maps for my data. The background for the map is:
library(rnaturalearth)
library(sf)
countries <- ne_countries(scale = "medium", ...
0
votes
1
answer
87
views
How to fix ggsankeyfier misaligned nodes and flows when facetting
I am trying to generate a sankey diagram using the ggsankeyfier package. The problem I have is that the nodes and flows are misalgined when using multiple facets as you can see in the picture. Does ...
2
votes
1
answer
114
views
Avoiding overlapping labels in geom_textpath
I have created a simple line chart with ggplot2 and would like to use geom_textpath to display the labelnames in the chart. The problem is that the labels currently overlap too much. How can I change ...
3
votes
2
answers
143
views
Issue with SpatVector wrapping when plotting
When plotting a SpatVector using ggplot2, if I define a projection using coord_sf(), it adds these lines that I think come from the data wrapping around the plot extent. Best way to fix?
library(...
1
vote
1
answer
72
views
How to create a stacked coefficients plot for multiple linear models in R?
I'm attempting to create a coefficient plot for multiple linear models using ggplot2 in R, but I'm facing an issue with overlapping points and error bars when displaying the estimates.
I've written a ...
0
votes
1
answer
89
views
stat_regline_equation() doesn't match stat_smooth() line
I'm getting an odd problem where I've attempted to plot a scatter graph and fit a quadratic regression line to it. I used stat_smooth() to make the line, and stat_regline_equation() to print the ...
2
votes
0
answers
107
views
How can i fix the Position_stack function that does not work in R?
I am using ggplot2 to create a horizontal bar chart. I use position_stack() function from the ggplot2 library version 4.0.0 on a Windows 11 computer.
packageVersion("ggplot2")
[1] ‘4.0.0’
...
2
votes
1
answer
78
views
Graph with bars and points, trouble getting both into legend
This legend should have an additional event "Spring", which is represented by a point in the legend, that is below the information about the bars. I can't get this to show up in the legend. ...
11
votes
2
answers
632
views
How can I create a 'listogram' in ggplot?
I am trying to recreate this graph I saw in this book, but instead make it as a histogram.
This is my code so far, but it is not looking as good:
set.seed(123)
library(dplyr)
library(ggplot2)
# ...
-3
votes
2
answers
79
views
X axis labels are not in sync with the data in ggplot
I have below data and ggplot
dat = structure(list(date = structure(c(19722, 19388, 19691, 19447,
19508, 19600, 19722, 19630, 19691, 19874, 19813, 19874, 19813,
19874, 19813, 19813, 19874, 19874, ...
1
vote
0
answers
83
views
r-graph-gallery.com: hierarchical edge bundling example not working
On r-graph-gallery.com one can find an example on how to create a hierarchical edge bundling network visualisation. The code looks like this:
# create a data frame giving the hierarchical structure of ...
4
votes
2
answers
158
views
Align a dendrogram with faceted time series
I am doing some time series clustering, and would like to align the dendrogram with the time series shapes. This is almost there:
library(ggplot2)
library(reshape2)
library(stats)
library(patchwork)
...
3
votes
0
answers
103
views
Vertical text with serif font in ggtext::element_textbox_simple
I'm trying to wrap long vertical text (like Y-axis label), that needs to be in serif font. I use ggtext::element_textbox_simple. However, it seems that text is being "squished" (spaces are ...
4
votes
3
answers
251
views
Modify the gtable of a ggplot2 and end up with a ggplot2 object without loss of information
I'm trying to write an extension for ggplot2 in R that lets a user add text annotations in the margins. My idea is to put the text in new rows/columns that get added to the plot's gtable. Hopefully ...
1
vote
1
answer
79
views
ggridges - controlling legend
I have a ridge plot where I'm colouring points by a grouping that doesn't affect the ridges. I would like to have a continuous point_colour legend using viridis, but can't figure out how to control it....
8
votes
2
answers
310
views
How to draw a double line in ggplot
How do I make the line in the graph above a double line like shown in below?
Some example code:
df <- data.frame(dose=c("D0.5", "D1", "D2"),
len=c(4.2,...