Got it thank you
From: Riley Finn
Sent: Thursday, August 23, 2018 10:24 PM
To: reichm...@sbcglobal.net
Cc: R-help@r-project.org
Subject: Re: [R] How to add a geom_smooth() line
Jeff,
You need to reshape your data frame. If you use ggplot, you will often have to
present your data in
Jeff,
You need to reshape your data frame. If you use ggplot, you will often
have to present your data in "long format"
Use the reshape2 package.
I made a sample data frame because you didn't provide one. I also change
your x and y labels because they made no sense.
data <- data.frame(
time
Hello,
if you want to fit different models to each of deliveries and launches,
use the wide format instead:
ggplot(data = data, aes(x = timeline)) +
geom_point(aes(y = deliveries), color = "blue") +
geom_smooth(aes(y = deliveries), color = "blue", method = lm, formula
= y ~ log(x)) +
Sorry, should be geom_smooth, not stat_smooth. They both work the same
way or very close to it.
Rui Barradas
On 24/08/2018 05:08, Rui Barradas wrote:
Hello,
The trick is to reshape your data from wide to long format.
There are many ways to do this, I will use package reshape2.
Make up a data
Hello,
The trick is to reshape your data from wide to long format.
There are many ways to do this, I will use package reshape2.
Make up a dataset:
library(ggplot2)
library(reshape2)
set.seed(9773)
n <- 20
data <- data.frame(timeline = 1:n,
deliveries = log(1:n) + runif(n),
R-help
I want to add two smooth lines (geom_smooth()) for each scatter plot. How
do I do that?
ggplot() +
geom_point(data=data, aes(x=timeline, y=deliveries), color="blue") +
geom_point(data=data, aes(x=timeline, y=launches), color="red") +
xlab("Deliveries") +
ylab("Launches")
6 matches
Mail list logo