Questions tagged [ggpmisc]

The ggpmisc tag should be used for questions related to the use of R package 'ggpmisc'.

The ggpmisc tag should be used for questions related to the use of R package 'ggpmisc'. Bug reports and requests for enhancements should not be posted here, but instead informed to the maintainer by raising an issue at https://bitbucket.org/aphalo/ggpmisc/issues.

The 'ggpmisc' R package is available through CRAN, and includes detailed documentation. This same documentation is also available in HTML format at http://docs.r4photobiology.info/ggpmisc and can be looked at without need to install the package. The source code of the package is in a public Git repository at https://bitbucket.org/aphalo/ggpmisc.

Functions are provided to convert time series objects into data frames or tibbles suitable for plotting with R package 'ggplot2'. To complement these functions ggplot() methods for "ts" and "xts" classes are also defined.

Different statistics, geometries and functions add facilities for labelling peaks and valleys, generating labels for fitted models including polynomial equations, highlighting deviations from a model fit, and for filtering-out regions of plot panels with high densities of observations (with stats designed to work nicely together with R package 'ggrepel').

Geometries for adding layers with inset tables, ggplots or 'grid' grobs are also defined together with versions of geom_text and geom_label that use 'grid' npc coordinates instead of data coordinates supported by new aesthetics npcxand npcy and corresponding scales.

81 questions
313
votes
10 answers

Add regression line equation and R^2 on graph

I wonder how to add regression line equation and R^2 on the ggplot. My code is: library(ggplot2) df <- data.frame(x = c(1:100)) df$y <- 2 + 3 * df$x + rnorm(100, sd = 40) p <- ggplot(data = df, aes(x = x, y = y)) + geom_smooth(method =…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
16
votes
3 answers

Showing equation of nls model with ggpmisc

R package ggpmisc can be used to show equation of lm model and poly model on ggplot2 (See here for reference). I wonder how I could show nls model equation results on ggplot2 using ggpmisc. Below is my MWE. library(ggpmisc) args <- list(formula = y…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
10
votes
3 answers

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 n_replicates <-…
Apatura
  • 65
  • 13
9
votes
3 answers

How to add R2 for each facet of ggplot in R?

Is there a way to first change the facet label from 1:3 to something like c(good, bad, ugly). Also, i would like to add R2 value to each of the facet. Below is my code- i tried a few things but didn't succeed. DF = data.frame(SUB = rep(1:3, each =…
Hydro
  • 1,057
  • 12
  • 25
7
votes
2 answers

Adding Regression Line Equation and R2 on SEPARATE LINES graph

A few years ago, a poster asked how to add regression line equation and R2 on ggplot graphs at the link below. Adding Regression Line Equation and R2 on graph The top solution was this: lm_eqn <- function(df){ m <- lm(y ~ x, df); eq <-…
Fiala Bumpers
  • 73
  • 1
  • 1
  • 5
6
votes
3 answers

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 first plot with has the regression equation plus…
Mark Neal
  • 996
  • 16
  • 52
6
votes
3 answers

Specifying formula for each facet using stat_poly_eq in ggplot2

I borrowed this example dataset from here: # Load library library(ggplot2) # Load data data(mtcars) # Plot data p <- ggplot(mtcars,aes(x = disp, y = mpg)) + geom_point() + facet_grid(gear ~ am) p <- p + geom_smooth(method="lm") print(p) In above…
Tianjian Qin
  • 525
  • 4
  • 14
5
votes
2 answers

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 text is ordinarily positioned with…
user697473
  • 2,165
  • 1
  • 20
  • 47
5
votes
1 answer

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 argument. I tried to add the eq.with.lhs argument in…
AlexC
  • 63
  • 7
5
votes
2 answers

How to annotate line plot with arrow and maximum value?

I am trying to annotate a line plot with an arrow pointing to the highest point in line plot and displaying an arrow and maximum value on the plot. I am using the mtcars dataset as my reference. Below is my code. e <- df$mpg ggplot(df, aes(x=e,…
Data_is_Power
  • 765
  • 3
  • 12
  • 30
4
votes
2 answers

How to position R-squared and equation in Facet mode?

I want to show the linear equation and the R-squared in the each plot in facet mode. This is my code so far. library("ggplot2") datos <- read.table("~/Documents/master2/plots/dosis_todos/datos.dat", header=TRUE, quote="\"") ggplot(datos, aes(x =…
murpholinox
  • 639
  • 1
  • 4
  • 14
4
votes
2 answers

Using `round` or `sprintf` function for Regression equation in ggpmisc and `dev="tikz"`

How can I control the numeric display in Regression equation by using round or sprintf function? I also could not figure out how to use dev="tikz" when using eq.with.lhs = "hat(Y)~=~". library(ggplot2) library(ggpmisc) # generate artificial…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
4
votes
1 answer

R package ggpmisc: Putting hat on y in Regression Equation

I'm using R package ggpmisc. Wonder how to put hat on y in Regression Equation or how to get custom Response and Explanatory variable name in Regression Equation on graph. library(ggplot2) library(ggpmisc) df <- data.frame(x1 =…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
3
votes
2 answers

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', scales = 'free')+ stat_cor(aes(color =…
Bryce Cook
  • 45
  • 4
3
votes
1 answer

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 <- ggplot(df,aes(x,y)) g <- g + geom_point(colour = "black") g…
Tim Ikata
  • 201
  • 1
  • 7
1
2 3 4 5 6