PhDMeiwp / ggtrendline

ggtrendline: An R Package for Adding Trendline and Confidence Interval to 'ggplot'.
https://CRAN.R-project.org/package=ggtrendline
25 stars 1 forks source link

ggtrendline is GREAT + quick Question #3

Closed sfd99 closed 2 years ago

sfd99 commented 2 years ago

Hi Weiping,

Really like the ggtrendline PKG. Easy to use and very helpful !.

The EQ text line and the R2 text line are by default very small and hard to read.

I was able to make the text font bigger,, using the eSize parameter = 5.

Q: How to position the EQ text line and the R2 text line more to the center of the plot?.

Right now, these 2 important text lines are almost "cut-off" on the left side of the plot...

I'd like to move them horizontally, a little to the right of the plot. ===>

Here's my test code, with the larger font...eSize=5

 x <- iris$Petal.Width
 y <- iris$Petal.Length
 group <- iris$Species
 ggtrendline(x,y,"exp3P",   eSize=5  )  + geom_point(aes(x,y,color=group))

Help, Weiping!

SFd99 San Francisco ggtrendline PKG v 1.0.3 latest version of R, RStudio and Ubuntu LINUX 20.04.

PhDMeiwp commented 2 years ago

Hi, sfd99

Thanks for your comments. In the ggtrendline package,

Try the following codes:

library(ggplot2)
library(ggtrendline)
x <- iris$Petal.Width
 y <- iris$Petal.Length
 group <- iris$Species
 ggtrendline(x, y, "exp3P", eSize = 5, eq.x = 1, eq.y = 6.5, rrp.x = 1, rrp.y = 5.8)  + 
                     geom_point(aes(x, y, color = group))

Best regards position

sfd99 commented 2 years ago

Perfect, Weiping!.

I guess my [Plot Panel] in Rstudio was sized too small, so the EQ and R2 lines were "cut-off" and I was losing some of that text...

Works great now!.

Thank you / 谢谢你

PS:

in addition to params: xlab and ylab , would also be nice to add a label parameter (glab ?) for the "group" LEGEND label, (shown on the right of the plot).

So you could add : glab="Species" for the iris example :-)

SFd99 San Francisco ggtrendline PKG v 1.0.3 latest version of R, RStudio and Ubuntu LINUX 20.04.

PhDMeiwp commented 2 years ago

Thank you.

The legend title could be modified as follows:

library(ggtrendline)
library(ggplot2)
x <- iris$Petal.Width
y <- iris$Petal.Length
group <- iris$Species

Option1: use labs()

ggtrendline(x, y, "exp3P", eSize = 5, eq.x = 1, eq.y = 6.5, rrp.x = 1, rrp.y = 5.8)  + 
    geom_point(aes(x, y, color = group))+
    labs(color = "DIY legend")

Option 2: use guides()

ggtrendline(x, y, "exp3P", eSize = 5, eq.x = 1, eq.y = 6.5, rrp.x = 1, rrp.y = 5.8)  + 
    geom_point(aes(x, y, color = group))+
    guides(color = guide_legend(title = "DIY2"))

Option 3: directly change the group name, i.e., Species <- iris$Species

library(ggtrendline)
library(ggplot2)
x <- iris$Petal.Width
y <- iris$Petal.Length
Species <- iris$Species
ggtrendline(x, y, "exp3P", eSize = 5, eq.x = 1, eq.y = 6.5, rrp.x = 1, rrp.y = 5.8)  + 
    geom_point(aes(x, y, color = Species))

Option 4: change x- ,y-axis labels and legend label.

library(ggtrendline)
library(ggplot2)
x <- iris$Petal.Width
y <- iris$Petal.Length
group <- iris$Species

ggtrendline(x, y, "exp3P", eSize = 5, eq.x = 1, eq.y = 6.5, rrp.x = 1, rrp.y = 5.8,
                    xlab = "DIY xname", ylab = "DIY yname")  + 
    geom_point(aes(x, y, color = group))+
    labs(color = "DIY legend")

Best regards

DIY

sfd99 commented 2 years ago

Ah, understood. Thank you, Weiping.

ggtrendline PKG is truly very good.

SFd99 San Francisco ggtrendline PKG v 1.0.3 latest version of R, RStudio and Ubuntu LINUX 20.04.