Questions tagged [ggpmisc]
The ggpmisc tag should be used for questions related to the use of R package 'ggpmisc'.
64
questions
0
votes
1
answer
40
views
How does lm() work when one axis is logarithmic?
I've tried fitting a linear equation to data with a logarithmic y axis a couple different ways. I seem to get the correct line and equation when I use stat_poly_line and stat_poly_eq. (See example ...
0
votes
1
answer
45
views
Is it possible to extract slope and intercept from multiple fitted lines into a tibble?
I'm trying to compare the slope and intercept of many separate fitted lines and would like to extract this information from the equations that are shown using stat_poly_eq. I am able to plot all of ...
1
vote
2
answers
31
views
stat_poly_eq() red text for significant p-value in facetwrap
I have a series of regressions wrapped into facet_wrap and I'm wondering whether it is possible to denote the text for significant pvals with red text or a "*" inside of the stat_poly_eq() [...
1
vote
1
answer
40
views
Remove data to the left and right of local minima
I have a lot of measurements where I get data that looks something like this:
# Generate example data
x <- 1:100
y <- 100*(1-exp(-0.3*x))
x2 <- 101:200
y2 <- rev(y)
df <- data.frame(&...
1
vote
0
answers
136
views
ggpmisc Error: package or namespace load failed for ‘ggpmisc’
I am trying to use the library ggpmisc and even though the installation went okey it gives me an error when I try to open the library. How can I solve it?
install.packages("ggpmisc")
...
3
votes
1
answer
63
views
Trend line changes depending on axis scale in ggplot2
I'm using ggplot2 and ggmics to generate a trend line.
library(ggplot2)
library(ggpmisc)
library(scales)
x <- c(5,2,6,8,9,1,3,6,8,2)
y <- c(4,7,2,5,7,9,5,2,1,3)
df <- data.frame(x,y)
g <-...
0
votes
1
answer
253
views
Trying to graph different linear regression models with ggplot and equation labels
Here is the dput for the dataset I'm working with:
structure(list(X = c(18, 19, 20, 17, 8, 15, 14, 16, 18, 14, 16,
13, 16, 17, 10, 18, 19, 25, 18, 13, 18, 16, 11, 17, 15, 18, 19,
16, 20, 17, 8, 18, ...
0
votes
1
answer
42
views
How can I scale a plot without affecting the data that is fit?
I have some data that is a bit crowded close to zero. I would thus like to use a logarithmic scale for the axes to get a clearer impression of those points. However, when I do this and I use the very ...
1
vote
2
answers
192
views
Can't get R2 values in two decimal using ggplot2 and ggpmisc
I am sorry that I don't know how to make reproducible example while asking for help here. Therefore, I am providing the code below and data; <350 KB here (data: https://easyupload.io/1r5xuo), if ...
0
votes
2
answers
166
views
How to add shapes for another factor in ggplot for regression model
I am trying to add shape to a regression model. Here is the example:
library(ggpubr)
data(iris)
iris$ran <- as.factor(rep(c(1:2), each = 75))
fit <- lm(Sepal.Length ~ Petal.Width+Species+ran, ...
2
votes
1
answer
374
views
Color ggscatter by R and P values
I'm plotting a wrapped ggscatter like the image below. What I want is to color differently according to the R and P values. For example, when P is not significant, I want the plot gray; when P is ...
1
vote
1
answer
700
views
R - How to make an expression containing a string and a dynamic variable bold in r/ggplot2
I am trying to make multiple facetted plots in r/ggplot2 that show R^2 and P values generated using the ggpmisc package, but format each line based on whether the P-value is below a certain number.
I ...
2
votes
2
answers
139
views
How to force trailing zeroes in 'polynom::polynomial' object? (specifically to modify behavior of stat_lm and stat_regline_equation from ggpubr)
I am trying to modify how stat_regline_equation displays the regression line equation on a plot made with ggscatter from the R package ggpubr. Specifically, I want to show a consistent number of ...
1
vote
1
answer
57
views
Does ggpmisc::stat_poly_eq recompute the trend line math to get the labels?
library(ggplot2)
library(dplyr)
x <- 1:100
y <- (x + x^2 + x^3) + rnorm(length(x), mean = 0, sd = mean(x^3) / 4)
my.data <- data.frame(x = x, y = y,
group = c("A&...
1
vote
1
answer
115
views
How to add number of observations to label of plot (with grouping and faceting) using ggpmisc::stat_poly_eq
x <- 1:100
y <- (x + x^2 + x^3) + rnorm(length(x), mean = 0, sd = mean(x^3) / 4)
my.data <- data.frame(x = x, y = y,
group = c("A", "B"),
...
1
vote
2
answers
208
views
Is there a way to add number of observations to plot label using ggpmisc::stat_poly_eq
x <- 1:100
y <- (x + x^2 + x^3) + rnorm(length(x), mean = 0, sd = mean(x^3) / 4)
my.data <- data.frame(x = x, y = y,
group = c("A", "B"),
...
0
votes
1
answer
109
views
ggpmisc::stat_poly_eq crashes when one group does not have enough data points
library(ggpmisc)
data <- mpg
table(data$class)
data$class[mpg$class=="2seater"] <- c(rep("2seater", 1), rep("compact", 4))
formula <- y ~ x + I(x^2)
ggplot(data, ...
1
vote
2
answers
134
views
Displaying regression lines based on P-value
I'm displaying linear regression models in plots using the ggpmisc package. I only want the regression line, p-value and r2-value to be showed in the plot if the p-value is less than 0.2. @Ricardo ...
1
vote
1
answer
264
views
Adding an offset term to a glm formula in geom_smooth and stat_fit_tidy
I have a data.frame with counts per two groups in three clusters to which I'm fitting a logistic regression (binomial glm with a logit link function), and plotting it all using ggplot2's geom_bar and ...
1
vote
0
answers
54
views
Calculating two LM in one plot using stat_poly_eq
I have calculated linear regression models between soil acetone emission and soil carbon content and plotted this in a graph like this:
Instead of showing one regression model in the plots I would ...
0
votes
1
answer
21
views
Discrepancy between gggmisc and broom packages in LM estimates
I'm trying to extract slope values from a number of linear regression models. I plotting acetone emission against water content on different days.
I have these graphs and models
I have tried to ...
1
vote
1
answer
170
views
correct positioning of ggplot insets with ggpmisc in facet
How can I flexibly position an inset using ggpmisc without changing the width and height of the inset itself?
library(tidyverse)
library(sf)
library(ggpmisc)
#data
nc <- st_read(system.file(&...
0
votes
1
answer
370
views
overlay of the legend of the estimated lines using the function stat_poly_eq
I adjusted different models considering the response variable (massaseca) as a function of (tempo) for each treatment level (teor) using the ggplot2 function combined with the stat_poly_eq function.
...
2
votes
3
answers
576
views
Is there a neat approach to label a ggplot plot with the equation and other statistics from geom_quantile()?
I'd like to include the relevant statistics from a geom_quantile() fitted line in a similar way to how I would for a geom_smooth(method="lm") fitted linear regression (where I've previously ...
1
vote
0
answers
103
views
"Error in f(...) : argument "table.theme" is missing, with no default" when using ggpmisc's annotate function for a table object
library(ggpmisc)
ggplot(Table, aes(x = Date, y = Value, group = Group)) +
geom_line(size = 0.2) +
scale_y_continuous("Value") +
scale_x_date("Date", breaks = "4 ...
1
vote
1
answer
430
views
How to format R2 and RMSE table added to a ggplot?
I am trying to add R2 and RMSE to a facetted ggplot. I am using the following code for that
library(caret)
library(tidyverse)
library(ggpmisc)
summ <- iris %>%
group_by(Species) %>%
...
0
votes
0
answers
234
views
R get linear regression equation for boxplots
I didn´t found a sufficient answer in this forum yet, so I decided to raise my own question.
I want to get the linear regression equation of a linear fit from a boxplot. I have this data:
library(...
0
votes
0
answers
183
views
Shiny-R: Display regression equation by groups under ggplot
I´ve looked for similiar questions, but wasn´t very sucessful.
I want to display my regression equations / coefficients under my ggplot as a text output.
Right now, I can display the regression ...
3
votes
3
answers
219
views
Editing *row* names of tabular display when using stat_fit_tb() in ggpmisc & ggplot
While stat_poly_eq() allows variable names to be changed using eq.with.lhs and eq.x.rhs, a similar functionality does not seem to be available within stat_fit_tb(), according to my reading of the ...
0
votes
1
answer
184
views
Adding a blocking factor in stat_poly_eq()
I'm fixing a linear regression with lm() like
model<-lm(y~x+a, data=dat)
where a is a blocking variable with multiple factor levels.
summary(model)
Call:
lm(formula = y ~ x, data = dat)
...
3
votes
2
answers
720
views
use npc units in annotate()
I have a ggplot object. I would like to add some text with annotate(), and I would like to specify the coordinates of the text in npc units. Is this possible?
This minimal example demonstrates how ...
0
votes
2
answers
316
views
Adding trend lines across groups and setting tick labels in a grouped violin plot or box plot
I have xy grouped data that I'm plotting using R's ggplot2 geom_violin adding regression trend lines:
Here are the data:
library(dplyr)
library(plotly)
library(ggplot2)
set.seed(1)
df <- data....
9
votes
3
answers
896
views
Produce an inset in each facet of an R ggplot while preserving colours of the original facet content
I would like to produce a graphic combining four facets of a graph with insets in each facet showing a detail of the respective plot. This is one of the things I tried:
#create data frame
...
0
votes
2
answers
542
views
Plotting multiple polynomial and linear regression lines on the same scatter plot
I've got a problem with the following regression models. I want to get two polynomial regression lines and one linear regression line on the same scatter plot. In addition, i want to show the ...
2
votes
3
answers
2k
views
Label ggplot with group names and their equation, possibly with ggpmisc?
I would like to label my plot, possibly using the equation method from ggpmisc to give an informative label that links to the colour and equation (then I can remove the legend altogether). For example,...
6
votes
3
answers
3k
views
Can we neatly align the regression equation and R2 and p value?
What is the best (easiest) approach to add neatly to a ggplot plot the regression equation, the R2, and the p-value (for the equation)? Ideally it should be compatible with groups and faceting.
This ...
0
votes
1
answer
30
views
ggpmisc clearing up confusion about summarized data lengths
I am getting this error message "Error in data.frame(mean_Flow, dates) : arguments imply differing number of rows: 84, 30274" and I know it is confused about which date function I want it to pull but ...
1
vote
1
answer
858
views
Change table theme when using ggpmisc::geom_table_npc
This question uses 'ggpmisc' version 0.3.4 or earlier, see answer below for version 0.3.5 or later.
I like the newish geom_table_npc in ggpmisc which provides a simple way to add a table to a ggplot ...
1
vote
1
answer
413
views
How to place stat_poly_eq labels outside of facet graph?
I have a facet graph and it's a pain having to tweak each individual r-square label, this includes moving them left to right, up and down, big and small. One may be larger than the other or hidden ...
0
votes
1
answer
1k
views
How to plot only Global Maximum Value using geom_text?
df%>%
group_by(approved_date)%>%
summarise(rev=sum(gmv))%>%
ggplot(aes(x = approved_date, y = rev)) +
geom_line() +
geom_smooth(method = 'auto', se = FALSE) +
labs(x = '...
1
vote
1
answer
793
views
facet_wrap text labelling issues with stat_fit_glance
I am wondering why the text is trending higher in the plots... it won't stay put with the facet_wrap or facet_grid. In a more complex dataset plot, the text is illegible because of the overlap.
...
0
votes
0
answers
78
views
Add R^2 value to plot
I'm new to R.
I have produced the following plot but want to know how to include an R^2 value on the linear model line using ggpmisc and the stat_poly_eq function. The code I have is as follows -
...
0
votes
1
answer
184
views
stat_fit_glance and generalized additive models (GAM) error
I am trying to add the p-value and R2 from mgcv::gam results to ggplot with facets. The sample dataframe and code are below. Is there a way to successfully paste the p-value and R2 on the ggplots?
DF ...
1
vote
2
answers
455
views
Coefficients per facet with output.type="numeric" in ggpmisc::stat_poly_eq
ggpmisc::stat_poly_eq has an option output.type = "numeric" allowing to get the estimates of the parameters of the fitted model. Below is my attempt to use it with facet_wrap. I get a different R² per ...
4
votes
1
answer
224
views
How to display different y labels in the equations using stat_poly_eq of ggpmisc
I'm trying to display the equations on the plot using the stat_poly_eq function of ggpmisc.
My problem is how to change the y= ... in the equation, by y1=... and y2=... by referring to the key ...
2
votes
1
answer
948
views
Labeling extrema with stat_peaks/stat_valleys produces duplicate labels
I extracted some longitudinal temperature data from a .nc weather dataset (ncdf4 package) and would like to label the local extrema with their respective dates from x-axis using ggplot2 and its ...
2
votes
0
answers
266
views
How do I facet plots that each contain an inset plot?
I'm trying to plot time series data for each "Type" in a dataset, and I want to include an inset of a zoomed in portion of the data for each plot. I can get the inset to work on each individual plot, ...
0
votes
1
answer
3k
views
Can't install package ‘ggpmisc’ is not available (for R version 3.5.0) [duplicate]
I'm trying to install ‘ggpmisc’ package in my Dockerfile, and I got the message :
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning: unable to access index ...
1
vote
2
answers
1k
views
Script won't run (Error in terms.formula(formula, data = data) : 'data' argument is of the wrong type
I have run the script below numerous times and it has worked until this morning, when it suddenly produced the error message:
(Error in terms.formula(formula, data = data) : 'data' argument is of
...
1
vote
1
answer
917
views
Add p-value to ggplot without creating a lm-obejct separately
I have to create a large (100+) number of ggplots of linear models. I would like to add the p-value (and potentially R2) to each plot. I know it is possible to do this using ggpmisc. Here, I employ ...