Questions tagged [ggpmisc]
The ggpmisc tag should be used for questions related to the use of R package 'ggpmisc'.
83
questions
1
vote
0
answers
40
views
How to add labels to my volcano plot in R
I am trying to create a volcano plot using R to show differentially expressed genes. I am trying to label the top 10 most significantly different genes using ggrepel with the gene_names from a the ...
1
vote
1
answer
70
views
How to force `stat_poly_line()` to use a specific non-zero y-intercept?
Using stat_poly_line() from package 'ggpmisc', one can fit a polynomial to data by default using lm() as method. You can force the fit through zero with either: formula = y ~ x + 0 or formula = y ~ x -...
3
votes
2
answers
112
views
ggpubr::stat_cor(), label.npc doesn't take into account geom_smooth output
library(ggplot2)
library(ggpubr)
data('iris')
ggplot(data = iris, aes(x = Petal.Length, y = Sepal.Length, color = Species))+
geom_point()+
geom_smooth(method = 'lm')+
facet_wrap('Species', ...
0
votes
1
answer
32
views
Show sqrt(y) ~ assign(sqrt(x)) relationship with `stat_poly_eq`, `stat_fit_tb` or `stat_fit_tidy`
require(utils)
x = runif(n = 10, min = 0.2, max = 1)
y = rnorm(n = 10, mean = 2.5, sd = .5)
df = expand.grid(x = x,
y = y)
I used the code below to plot the sqrt(y) ~ assign(sqrt(x)) ...
1
vote
0
answers
128
views
problem plotting linear regression equation with ggpmisc in R studio
I am trying to plot linear regression and display corresponding equations and R squared. I used the #following code:
ch= factor (rep(c("c1", "c2", "c3", "c4"),3,...
1
vote
2
answers
96
views
How to change the label on each quadrant of the scatterplot from count of observations into percent?
The code is:
library(gginnards)
library(ggpmisc)
library(ggplot2)
set.seed(4321)
x <- 1:100
y <- rnorm(length(x), mean = 10)
my.data <- data.frame(x, y)
ggplot(my.data, aes(x, y)) +
...
0
votes
0
answers
91
views
How do I change the start of my trendline to be 0 using ggpmisc stat_poly_line?
I have a scatter plot in R ggplot2 and I am using ggpmisc's stat_poly_line to draw a trendline and calculate R2, my problem is that due to my data, my trendline starts at a value different from 0 and ...
0
votes
1
answer
47
views
Pull out Regression Eqn from ggplot
Here is a reproducible example of my problem:
library(ggplot2)
library(dplyr)
library(ggpmisc)
df <- mtcars %>%
filter(cyl==4)
ggplot(mtcars,aes(x=disp,y=hp))+
geom_point() +
...
2
votes
0
answers
237
views
Manual position of stat_poly_eq labels with facet_wrap being another variable than e.g. color does not work
I have a dataframe (df) which looks something like this:
#Creating sample data
RE <- c(0.95, 0.8, 0.7, 0.85, 0.5, 0.3, 1, 0.8, 0.2, 0.95, 0.4, 0)
TimeSinceStart <- c(10, 20, 30, 10, 20, 30, 10, ...
0
votes
0
answers
200
views
How can I adjust text formatting in stat_poly_eq?
I'm trying to adjust an equation formatting which is shown while using ggplot2 (ver. 3.3.5) and ggpmisc (ver. 0.5.1) with stat_poly_eq.
All works just fine but for the case when the coefficients in ...
3
votes
3
answers
473
views
Modifying the decimal mark of stat_poly_eq
I use the stat_poly_eq function from the ggpmisc package to add the regression equation in my ggplots. It works perfectly. However, I'd like to change the decimal mark of the equation from period to ...
2
votes
1
answer
386
views
How to fill the background of a stat_poly_eq equation (ggpmisc) using ggplot2?
Is there a way to fill the background of a stat_poly_eq equation ggpmisc with white color (or any other color) so that the black lines of the panel.grid are hidden?
# Data
df <- data.frame(x = c(1:...
0
votes
0
answers
118
views
Display line equation in subtitle of ggplot?
Below is the code for creating bulk hydrographs from a formatted .csv file in a network drive. stat_regline_equation(data=cont, aes(x,y)) allows me to print the continuous data line equation on the ...
0
votes
0
answers
68
views
How to automatically add R^2 to a graph with facet wrap using ggplot2? [duplicate]
I am trying to add R^2 values to each facet in a ggplot2 graph. This is the code I have so far and this is what the graph looks like currently.
ggplot(BB_new, aes(x=Date, y=pH, color=Treatment)) +
...
0
votes
1
answer
111
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 ...
1
vote
1
answer
242
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
275
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
47
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
1k
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")
...
2
votes
1
answer
530
views
R scientific notation in stat_poly_eq
I am currently using the code for stat_poly_eq in ggplot2 and was wondering if there is a way to always get the values on the graph in xe+1? So far it only gives me the Xx10^1 when the value is very ...
3
votes
1
answer
176
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
1k
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
82
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 ...
2
votes
2
answers
529
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
464
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
915
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
2
answers
392
views
Gamma(log) in stat_poly_eq
I'm having some trouble having stat_poly_eq print the correct formula within my plot. My current plot is plotted as follows.
ggplot(DataSB,aes(x=Year,y=Kilos))+
geom_point(shape=21, size=3, color=&...
1
vote
1
answer
2k
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
242
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
145
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
340
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
3
answers
717
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"),
...
1
vote
1
answer
730
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
407
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
442
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
88
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
28
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
341
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
884
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
1k
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
150
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
880
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
617
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
248
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
326
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 ...
1
vote
1
answer
404
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)
...
5
votes
2
answers
1k
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
617
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....
10
votes
3
answers
1k
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
1k
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 ...