Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread rain1290--- via R-help
Hi Rui,

Yes! This worked just fine! Thank you so, so much for your time and patience! 

-Original Message-
From: Rui Barradas 
To: rain1290 ; r-help 
Sent: Thu, Jun 6, 2019 3:25 pm
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

Try this.


values_to_plot <- c("onepctCO2MEDIAN", "RCP4.5MEDIAN", "RCP8.5MEDIAN")
sub_df <- subset(NewestdataUltra, L1 %in% values_to_plot)

ggplot(sub_df, aes(x, value, colour = L1)) +
  geom_point() +
  scale_color_manual(values = c("green", "red", "blue")) +
  geom_smooth(method = lm)


If you have more L1 values to plot, add more colors. The number of 
colors must be equal to

length(values_to_plot)


Hope this helps,

Rui Barradas

Às 17:49 de 06/06/19, rain1...@aim.com escreveu:
> Hi Rui, NewestdataUltra looks like this (Note that "HistoricalMEDIAN" is 
> hidden, but it follows "RCP8.5MEDIAN" listing the same way): x variable 
> value L1 1 0.0 y 0. onepctCO2MEDIAN 2 0.006794447 y 
> 4.90024902 onepctCO2MEDIAN 3 0.014288058 y 0.1607 onepctCO2MEDIAN 4 
> 0.022087920 y 6.63491326 onepctCO2MEDIAN 5 0.030797357 y -1.24295056 
> onepctCO2MEDIAN 6 0.038451072 y 1.56433744 onepctCO2MEDIAN 7 0.048087904 
> y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y 2.20700446 onepctCO2MEDIAN 
> 9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10 0.080524530 y -1.09135062 
> onepctCO2MEDIAN 11 0.092760246 y 0.40999399 onepctCO2MEDIAN 12 
> 0.103789609 y -0.12597268 onepctCO2MEDIAN 13 0.116953168 y -2.41382534 
> onepctCO2MEDIAN 14 0.129253298 y 7.08902570 onepctCO2MEDIAN 15 
> 0.141710050 y -0.75935388 onepctCO2MEDIAN 16 0.156002052 y 0.04544160 
> onepctCO2MEDIAN 17 0.170648172 y -1.53496826 onepctCO2MEDIAN 18 
> 0.185318425 y 6.55242014 onepctCO2MEDIAN 19 0.199463055 y -0.83125628 
> onepctCO2MEDIAN 20 0.213513337 y -2.50991826 onepctCO2MEDIAN 21 
> 0.228839271 y 0.13659682 onepctCO2MEDIAN 22 0.246981293 y -1.37198445 
> onepctCO2MEDIAN 23 0.263012767 y -0.87129883 onepctCO2MEDIAN 24 
> 0.278505564 y 0.66325836 onepctCO2MEDIAN 25 0.293658361 y 0.79380363 
> onepctCO2MEDIAN 26 0.310747266 y 3.48806374 onepctCO2MEDIAN 27 
> 0.325990349 y -4.46122081 onepctCO2MEDIAN 28 0.342517540 y 0.08717340 
> onepctCO2MEDIAN 29 0.362751633 y -1.41715777 onepctCO2MEDIAN 30 
> 0.380199537 y -0.99565082 onepctCO2MEDIAN 31 0.394992948 y 0.32155262 
> onepctCO2MEDIAN 32 0.414373398 y 3.14038657 onepctCO2MEDIAN 33 
> 0.430690214 y -0.73760988 onepctCO2MEDIAN 34 0.449738145 y -2.48605407 
> onepctCO2MEDIAN 35 0.470167458 y -3.42358584 onepctCO2MEDIAN 36 
> 0.489019871 y 0.48247475 onepctCO2MEDIAN 37 0.507242471 y -0.97853863 
> onepctCO2MEDIAN 38 0.524314284 y 8.53596838 onepctCO2MEDIAN 39 
> 0.543750525 y 5.48447420 onepctCO2MEDIAN 40 0.564234197 y 3.21493666 
> onepctCO2MEDIAN 41 0.583679616 y 3.91689160 onepctCO2MEDIAN 42 
> 0.601459444 y 4.49070196 onepctCO2MEDIAN 43 0.619924664 y 6.54104103 
> onepctCO2MEDIAN 44 0.639932007 y 4.80686500 onepctCO2MEDIAN 45 
> 0.661347181 y 8.15101701 onepctCO2MEDIAN 46 0.684117317 y 0.26974132 
> onepctCO2MEDIAN 47 0.704829752 y -0.18075007 onepctCO2MEDIAN 48 
> 0.725045770 y 9.71812491 onepctCO2MEDIAN 49 0.745165825 y 1.54064657 
> onepctCO2MEDIAN 50 0.765016139 y -1.64760409 onepctCO2MEDIAN 51 
> 0.783461511 y 4.80246029 onepctCO2MEDIAN 52 0.806382924 y 4.04215160 
> onepctCO2MEDIAN 53 0.829241335 y 9.37565122 onepctCO2MEDIAN 54 
> 0.849924415 y 5.33050497 onepctCO2MEDIAN 55 0.871352434 y 7.54458026 
> onepctCO2MEDIAN 56 0.893632233 y 6.46795471 onepctCO2MEDIAN 57 
> 0.916052133 y 2.80960651 onepctCO2MEDIAN 58 0.938579470 y 5.39216613 
> onepctCO2MEDIAN 59 0.959907651 y 7.20436888 onepctCO2MEDIAN 60 
> 0.981643587 y 3.33508065 onepctCO2MEDIAN 61 1.004116774 y 8.86907070 
> onepctCO2MEDIAN 62 1.028363466 y 1.78612989 onepctCO2MEDIAN 63 
> 1.054009140 y 6.25550382 onepctCO2MEDIAN 64 1.072440803 y 7.60792365 
> onepctCO2MEDIAN 65 1.094457805 y 7.68714831 onepctCO2MEDIAN 66 
> 1.123176277 y 4.77877639 onepctCO2MEDIAN 67 1.149430871 y 12.71105018 
> onepctCO2MEDIAN 68 1.170912921 y -0.71562844 onepctCO2MEDIAN 69 
> 1.196743071 y 1.64908992 onepctCO2MEDIAN 70 1.218625903 y 3.03630241 
> onepctCO2MEDIAN 71 1.241868377 y 4.29747688 onepctCO2MEDIAN 72 
> 1.267941594 y 1.95437781 onepctCO2MEDIAN 73 1.290708780 y 3.99869637 
> onepctCO2MEDIAN 74 1.31389 y 4.51794725 onepctCO2MEDIAN 75 
> 1.339045882 y 0.93379048 onepctCO2MEDIAN 76 1.362803459 y 3.30507700 
> onepctCO2MEDIAN 77 1.384450197 y 3.54229702 onepctCO2MEDIAN 78 
> 1.409720302 y 5.99736597 onepctCO2MEDIAN 79 1.435851157 y 0.50818686 
> onepctCO2MEDIAN 80 1.455592215 y 7.96616301 onepctCO2MEDIAN 81 
> 1.479495347 y 9.94604963 onepctCO2MEDIAN 82 1.506051958 y 3.79083717 
> onepctCO2MEDIAN 83 1.525728464 y 2.57358469 onepctCO2

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread Rui Barradas
RCP4.5MEDIAN 209 1.127809421 y -0.65627179 
RCP4.5MEDIAN 210 1.133265961 y 12.02566969 RCP4.5MEDIAN 211 1.138549712 
y -1.04260843 RCP4.5MEDIAN 212 1.143910237 y -6.47611327 RCP4.5MEDIAN 
213 1.149437787 y 8.88410567 RCP4.5MEDIAN 214 1.154488347 y -4.24916247 
RCP4.5MEDIAN 215 1.159872903 y 7.90741918 RCP4.5MEDIAN 216 1.165477487 y 
-3.91386711 RCP4.5MEDIAN 217 1.171103424 y 1.02370701 RCP4.5MEDIAN 218 
1.177498256 y -3.71206616 RCP4.5MEDIAN 219 1.184003888 y -1.05694182 
RCP4.5MEDIAN 220 1.190395856 y 1.10501459 RCP4.5MEDIAN 221 1.197284280 y 
2.67668639 RCP4.5MEDIAN 222 1.204590551 y 2.21693031 RCP4.5MEDIAN 223 
1.210807614 y 2.90252830 RCP4.5MEDIAN 224 1.216470664 y 2.75093766 
RCP4.5MEDIAN 225 1.221914148 y -0.73815245 RCP4.5MEDIAN 226 1.227580480 
y 3.58554626 RCP4.5MEDIAN 227 1.233317788 y 10.89961658 RCP4.5MEDIAN 228 
1.238093406 y 3.23374387 RCP4.5MEDIAN 229 0.466622908 y -1.92366466 
RCP8.5MEDIAN 230 0.474211509 y 4.09292949 RCP8.5MEDIAN 231 0.480383051 y 
-0.84736312 RCP8.5MEDIAN 232 0.486304903 y -0.80597889 RCP8.5MEDIAN 233 
0.492151615 y -0.50244413 RCP8.5MEDIAN 234 0.499312643 y 3.07785701 
RCP8.5MEDIAN 235 0.508859905 y -6.15175322 RCP8.5MEDIAN 236 0.518758845 
y -0.51590144 RCP8.5MEDIAN 237 0.528675758 y 3.33135956 RCP8.5MEDIAN 238 
0.538928423 y 2.62280891 RCP8.5MEDIAN 239 0.549621221 y -6.90096009 
RCP8.5MEDIAN 240 0.560062840 y -3.45706029 RCP8.5MEDIAN 241 0.570860791 
y 1.36192518 RCP8.5MEDIAN 242 0.581923368 y 0.34822359 RCP8.5MEDIAN 243 
0.592628298 y 3.06882935 RCP8.5MEDIAN 244 0.604230648 y -3.56142825 
RCP8.5MEDIAN 245 0.615975167 y 10.35932554 RCP8.5MEDIAN 246 0.627448279 
y 10.21751629 RCP8.5MEDIAN 247 0.639401050 y 3.31040335 RCP8.5MEDIAN 248 
0.651949591 y -0.53558775 RCP8.5MEDIAN 249 0.664634427 y 2.66081860 
RCP8.5MEDIAN 250 0.677343552 y 3.21379656 RCP8.5MEDIAN [ reached 'max' / 
getOption("max.print") -- omitted 212 rows ]



If I wanted scatter plots and regression lines of onepctCO2MEDIAN, 
RCP4.5MEDIAN and RCP8.5MEDIAN, would I do something like this? :
ggplot(subset(NewestdataUltra, L1 != 'onepctCO2MEDIAN'), aes(x, value, 
colour = L1)) + geom_point() + scale_color_manual(values =c("green", 
"blue" "red", "black")) + geom_smooth(method = lm, se=FALSE)

**//___^
Thanks,

-----Original Message-
From: Rui Barradas 
To: rain1290 ; r-help 
Sent: Thu, Jun 6, 2019 11:53 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

It's impossible to say without seeing the data.

What is the return value of

df_tmp <- subset(NewestdataUltra, L1 != 'onepctCO2MEDIAN')
unique(df_tmp$L1)

The number of colors must be the same as

length(unique(df_tmp$L1))


Hope this helps,

Rui Barradas

Às 16:49 de 06/06/19, rain1...@aim.com <mailto:rain1...@aim.com> escreveu:
 > Hi Rui,
 >
 > Yes, you are right. It should be this, but I tried with only 3 colors,
 > as you suggested:
 >
 > ggplot(subset(NewestdataUltra, L1 != 'onepctCO2MEDIAN'), aes(x, value,
 > colour = L1)) + geom_point() + scale_color_manual(values =c("green",
 > "blue" "red")) + geom_smooth(method = lm, se=FALSE)
 >
 > **//___^
 > **//___^I still end up with the same error, however, when I specify only
 > 3 colors. Why could this be?
 >
 >
 > -Original Message-
 > From: Rui Barradas mailto:ruipbarra...@sapo.pt>>
 > To: rain1290 mailto:rain1...@aim.com>>; r-help 
mailto:r-help@R-project.org>>

 > Sent: Thu, Jun 6, 2019 11:18 am
 > Subject: Re: [R] Plotting more than one regression line in ggplot
 >
 > Hello,
 >
 > 1) In the text you say your dataset is named NewestdataUltra but in the
 > ggplot instruction it's Newestdata. One of these is wrong.
 >
 > 2) Is it onepctCO2MEDIAN or RCPonepctCO2MEDIAN?
 >
 > 3) You are filtering out the value in point ) above. So you only plot 3
 > regression lines, you don't need 4 colors.
 >
 >
 > Hope this helps,
 >
 > Rui Barradas
 >
 > Às 15:35 de 06/06/19, rain1...@aim.com <mailto:rain1...@aim.com> 
<mailto:rain1...@aim.com <mailto:rain1...@aim.com>> escreveu:

 >  > Hi Rui (and everyone),
 >  >
 >  >
 >  > Thank you for this! Yes, this did work fine, as I can see my scatter
 >  > plots and regression lines on the same plot, along with the 
appropriate

 >  > coloring scheme! :)
 >  >
 >  > Just one last question concerning this - I melted other dataframes 
into

 >  > my new "NewestdataUltra". I now have 4 objects listed in there in this
 >  > order (starting from the top of the list): "onepctCO2MEDIAN",
 >  > "RCP4.5MEDIAN", RCP8.5MEDIAN", and "HistoricalMEDIAN". I tried 
plotting

 >  > colored scattered plots and regression lines for these in this ma

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread rain1290--- via R-help
9150RCP4.5MEDIAN
186 0.950999217y  1.86490308RCP4.5MEDIAN
187 0.958795701y  8.32126161RCP4.5MEDIAN
188 0.966310396y 10.15048356RCP4.5MEDIAN
189 0.973635493y  6.68925964RCP4.5MEDIAN
190 0.980834088y -1.01615369RCP4.5MEDIAN
191 0.987694790y  0.20892853RCP4.5MEDIAN
192 0.994548581y -1.52787222RCP4.5MEDIAN
193 1.001274595y -0.72374597RCP4.5MEDIAN
194 1.007810612y  2.26062309RCP4.5MEDIAN
195 1.014270389y -2.40270340RCP4.5MEDIAN
196 1.022719711y -1.94548262RCP4.5MEDIAN
197 1.032070810y -1.13053235RCP4.5MEDIAN
198 1.041118812y  0.56107969RCP4.5MEDIAN
199 1.050189571y  3.27941835RCP4.5MEDIAN
200 1.059380475y  3.01333588RCP4.5MEDIAN
201 1.067877585y  4.87457336RCP4.5MEDIAN
202 1.076078766y  1.02457895RCP4.5MEDIAN
203 1.084707357y  4.49174869RCP4.5MEDIAN
204 1.093223180y  8.24629303RCP4.5MEDIAN
205 1.101414382y -0.03364132RCP4.5MEDIAN
206 1.108886304y  9.12509848RCP4.5MEDIAN
207 1.115482896y  1.74254621RCP4.5MEDIAN
208 1.121856558y  2.27004536RCP4.5MEDIAN
209 1.127809421y -0.65627179RCP4.5MEDIAN
210 1.133265961y 12.02566969RCP4.5MEDIAN
211 1.138549712y -1.04260843RCP4.5MEDIAN
212 1.143910237y -6.47611327RCP4.5MEDIAN
213 1.149437787y  8.88410567RCP4.5MEDIAN
214 1.154488347y -4.24916247RCP4.5MEDIAN
215 1.159872903y  7.90741918RCP4.5MEDIAN
216 1.165477487y -3.91386711RCP4.5MEDIAN
217 1.171103424y  1.02370701RCP4.5MEDIAN
218 1.177498256y -3.71206616RCP4.5MEDIAN
219 1.184003888y -1.05694182RCP4.5MEDIAN
220 1.190395856y  1.10501459RCP4.5MEDIAN
221 1.197284280y  2.67668639RCP4.5MEDIAN
222 1.204590551y  2.21693031RCP4.5MEDIAN
223 1.210807614y  2.90252830RCP4.5MEDIAN
224 1.216470664y  2.75093766RCP4.5MEDIAN
225 1.221914148y -0.73815245RCP4.5MEDIAN
226 1.227580480y  3.58554626RCP4.5MEDIAN
227 1.233317788y 10.89961658RCP4.5MEDIAN
228 1.238093406y  3.23374387RCP4.5MEDIAN
229 0.466622908y -1.92366466RCP8.5MEDIAN
230 0.474211509y  4.09292949RCP8.5MEDIAN
231 0.480383051y -0.84736312RCP8.5MEDIAN
232 0.486304903y -0.80597889RCP8.5MEDIAN
233 0.492151615y -0.50244413RCP8.5MEDIAN
234 0.499312643y  3.07785701RCP8.5MEDIAN
235 0.508859905y -6.15175322RCP8.5MEDIAN
236 0.518758845y -0.51590144RCP8.5MEDIAN
237 0.528675758y  3.33135956RCP8.5MEDIAN
238 0.538928423y  2.62280891RCP8.5MEDIAN
239 0.549621221y -6.90096009RCP8.5MEDIAN
240 0.560062840y -3.45706029RCP8.5MEDIAN
241 0.570860791y  1.36192518RCP8.5MEDIAN
242 0.581923368y  0.34822359RCP8.5MEDIAN
243 0.592628298y  3.06882935RCP8.5MEDIAN
244 0.604230648y -3.56142825RCP8.5MEDIAN
245 0.615975167y 10.35932554RCP8.5MEDIAN
246 0.627448279y 10.21751629RCP8.5MEDIAN
247 0.639401050y  3.31040335RCP8.5MEDIAN
248 0.651949591y -0.53558775RCP8.5MEDIAN
249 0.664634427y  2.66081860RCP8.5MEDIAN
250 0.677343552y  3.21379656RCP8.5MEDIAN
 [ reached 'max' / getOption("max.print") -- omitted 212 rows ]
If I wanted scatter plots and regression lines of onepctCO2MEDIAN, RCP4.5MEDIAN 
and RCP8.5MEDIAN, would I do something like this? 
:ggplot(subset(NewestdataUltra, L1 != 'onepctCO2MEDIAN'), aes(x, value, colour 
= L1)) + geom_point() + scale_color_manual(values =c("green", "blue" "red", 
"black")) + geom_smooth(method = lm, se=FALSE)
Thanks,
-Original Message-
From: Rui Barradas 
To: rain1290 ; r-help 
Sent: Thu, Jun 6, 2019 11:53 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

It's impossible to say without seeing the data.

What is the return value of

df_tmp <- subset(NewestdataUltra, L1 != 'onepctCO2MEDIAN')
unique(df_tmp$L1)

The number of colors must be the same as

length(unique(df_tmp$L1))


Hope this helps,

Rui Barradas

Às 16:49 de 06/06/19, rain1...@aim.com escreveu:
> Hi Rui,
> 
> Yes, you are right. It should be this, but I tried with only 3 colors, 
> as you suggested:
> 
> ggplot(subset(NewestdataUltra, L1 != 'onepctCO2MEDIAN'), aes(x, value, 
> colour = L1)) + geom_point() + scale_color_manual(values =c("green", 
> "blue" "red")) + geom_smooth(method = lm, se=FALSE)
> 
> **//___^
> **//___^I still end up with the same error, however, when I specify only 
> 3 colors. Why could this be?
> 
> 
> -Original Message-

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread Rui Barradas

Hello,

It's impossible to say without seeing the data.

What is the return value of

df_tmp <- subset(NewestdataUltra, L1 != 'onepctCO2MEDIAN')
unique(df_tmp$L1)

The number of colors must be the same as

length(unique(df_tmp$L1))


Hope this helps,

Rui Barradas

Às 16:49 de 06/06/19, rain1...@aim.com escreveu:

Hi Rui,

Yes, you are right. It should be this, but I tried with only 3 colors, 
as you suggested:


ggplot(subset(NewestdataUltra, L1 != 'onepctCO2MEDIAN'), aes(x, value, 
colour = L1)) + geom_point() + scale_color_manual(values =c("green", 
"blue" "red")) + geom_smooth(method = lm, se=FALSE)


**//___^
**//___^I still end up with the same error, however, when I specify only 
3 colors. Why could this be?



-Original Message-
From: Rui Barradas 
To: rain1290 ; r-help 
Sent: Thu, Jun 6, 2019 11:18 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

1) In the text you say your dataset is named NewestdataUltra but in the
ggplot instruction it's Newestdata. One of these is wrong.

2) Is it onepctCO2MEDIAN or RCPonepctCO2MEDIAN?

3) You are filtering out the value in point ) above. So you only plot 3
regression lines, you don't need 4 colors.


Hope this helps,

Rui Barradas

Às 15:35 de 06/06/19, rain1...@aim.com <mailto:rain1...@aim.com> escreveu:
 > Hi Rui (and everyone),
 >
 >
 > Thank you for this! Yes, this did work fine, as I can see my scatter
 > plots and regression lines on the same plot, along with the appropriate
 > coloring scheme! :)
 >
 > Just one last question concerning this - I melted other dataframes into
 > my new "NewestdataUltra". I now have 4 objects listed in there in this
 > order (starting from the top of the list): "onepctCO2MEDIAN",
 > "RCP4.5MEDIAN", RCP8.5MEDIAN", and "HistoricalMEDIAN". I tried plotting
 > colored scattered plots and regression lines for these in this manner:
 >
 > ggplot(subset(Newestdata, L1 != 'RCPonepctCO2MEDIAN'), aes(x, value,
 > colour = L1)) + geom_point() + scale_color_manual(values =c("green",
 > "blue" "red", "black")) + geom_smooth(method = lm, se=FALSE)
 >
 > However, I received this error:
 >
 > Error: unexpected string constant in "ggplot(subset(NewestdataUltra, L1
 > != 'RCPonepctCO2MEDIAN'), aes(x, value, colour = L1)) + geom_point() +
 > scale_color_manual(values =c("green", "blue" "red""
 >
 > **//___^
 >
 > Why would this error appear?  I think that I assigned the colors
 > correctly to each of the four objects in question, so why would this 
occur?

 >
 > Thank you, once again!
 >
 > -Original Message-
 > From: Rui Barradas mailto:ruipbarra...@sapo.pt>>
 > To: rain1290 mailto:rain1...@aim.com>>; r-help 
mailto:r-help@R-project.org>>

 > Sent: Thu, Jun 6, 2019 6:52 am
 > Subject: Re: [R] Plotting more than one regression line in ggplot
 >
 > Hello,
 >
 > You are confusing some of the values of L1 with L1 itself.
 > If you just want two of those values in your plot, "onepctCO2MEDIAN" and
 > "RCP8.5MEDIAN", you need to subset the data filtering out the rows with
 > L1 == "RCP4.5MEDIAN".
 >
 > And please forget geom_jitter, it is completely inappropriate for the
 > type of scatter plot you are trying to graph. You jitter when there is
 > overplotting, not as a general purpose technique.
 >
 > Here is one way to do it.
 >
 >
 > ggplot(subset(NewestdataUltra, L1 != 'RCP4.5MEDIAN'),
 >          aes(x, value, colour = L1)) +
 >    geom_point() +
 >    scale_color_manual(values = c("green", "red")) +
 >    geom_smooth(method = lm)
 >
 >
 > Hope this helps,
 >
 > Rui Barradas
 >
 > Às 22:37 de 05/06/19, rain1...@aim.com <mailto:rain1...@aim.com> 
<mailto:rain1...@aim.com <mailto:rain1...@aim.com>> escreveu:

 >  > Hi Rui (and everyone),
 >  >
 >  > Thank you so much for your response! Much appreciated!
 >  >
 >  > What if I wanted I create several regression lines and scatter 
plots in

 >  > the same ggplot using a "melted" dataset? I would like to create a
 >  > scatter plot and regression line for both the objects of
 >  > "onepctCO2MEDIAN" and "RCP8.5MEDIANThis melted dataset looks like 
this:

 >  >
 >  >
 >  >  >NewestdataUltra
 >  >
 >  > x variable value L1 1 0.0 y 0. onepctCO2MEDIAN 2
 >  > 0.006794447 y 4.90024902 onepctCO2MEDIAN 3 0.014288058 y 0.1607
 >  > onepctCO2MEDIAN 4 0.022087920 y 6.63491326 onepctCO2MEDIAN 5 
0.030797357
 >  > y -1.24295056

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread rain1290--- via R-help
Hi Rui,

Yes, you are right. It should be this, but I tried with only 3 colors, as you 
suggested:
ggplot(subset(NewestdataUltra, L1 != 'onepctCO2MEDIAN'), aes(x, value, colour = 
L1)) + geom_point() + scale_color_manual(values =c("green", "blue" "red")) + 
geom_smooth(method = lm, se=FALSE)
I still end up with the same error, however, when I specify only 3 colors. Why 
could this be?

-Original Message-
From: Rui Barradas 
To: rain1290 ; r-help 
Sent: Thu, Jun 6, 2019 11:18 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

1) In the text you say your dataset is named NewestdataUltra but in the 
ggplot instruction it's Newestdata. One of these is wrong.

2) Is it onepctCO2MEDIAN or RCPonepctCO2MEDIAN?

3) You are filtering out the value in point ) above. So you only plot 3 
regression lines, you don't need 4 colors.


Hope this helps,

Rui Barradas

Às 15:35 de 06/06/19, rain1...@aim.com escreveu:
> Hi Rui (and everyone),
> 
> 
> Thank you for this! Yes, this did work fine, as I can see my scatter 
> plots and regression lines on the same plot, along with the appropriate 
> coloring scheme! :)
> 
> Just one last question concerning this - I melted other dataframes into 
> my new "NewestdataUltra". I now have 4 objects listed in there in this 
> order (starting from the top of the list): "onepctCO2MEDIAN", 
> "RCP4.5MEDIAN", RCP8.5MEDIAN", and "HistoricalMEDIAN". I tried plotting 
> colored scattered plots and regression lines for these in this manner:
> 
> ggplot(subset(Newestdata, L1 != 'RCPonepctCO2MEDIAN'), aes(x, value, 
> colour = L1)) + geom_point() + scale_color_manual(values =c("green", 
> "blue" "red", "black")) + geom_smooth(method = lm, se=FALSE)
> 
> However, I received this error:
> 
> Error: unexpected string constant in "ggplot(subset(NewestdataUltra, L1 
> != 'RCPonepctCO2MEDIAN'), aes(x, value, colour = L1)) + geom_point() + 
> scale_color_manual(values =c("green", "blue" "red""
> 
> **//___^
> 
> Why would this error appear?  I think that I assigned the colors 
> correctly to each of the four objects in question, so why would this occur?
> 
> Thank you, once again!
> 
> -Original Message-
> From: Rui Barradas 
> To: rain1290 ; r-help 
> Sent: Thu, Jun 6, 2019 6:52 am
> Subject: Re: [R] Plotting more than one regression line in ggplot
> 
> Hello,
> 
> You are confusing some of the values of L1 with L1 itself.
> If you just want two of those values in your plot, "onepctCO2MEDIAN" and
> "RCP8.5MEDIAN", you need to subset the data filtering out the rows with
> L1 == "RCP4.5MEDIAN".
> 
> And please forget geom_jitter, it is completely inappropriate for the
> type of scatter plot you are trying to graph. You jitter when there is
> overplotting, not as a general purpose technique.
> 
> Here is one way to do it.
> 
> 
> ggplot(subset(NewestdataUltra, L1 != 'RCP4.5MEDIAN'),
>          aes(x, value, colour = L1)) +
>    geom_point() +
>    scale_color_manual(values = c("green", "red")) +
>    geom_smooth(method = lm)
> 
> 
> Hope this helps,
> 
> Rui Barradas
> 
> Às 22:37 de 05/06/19, rain1...@aim.com <mailto:rain1...@aim.com> escreveu:
>  > Hi Rui (and everyone),
>  >
>  > Thank you so much for your response! Much appreciated!
>  >
>  > What if I wanted I create several regression lines and scatter plots in
>  > the same ggplot using a "melted" dataset? I would like to create a
>  > scatter plot and regression line for both the objects of
>  > "onepctCO2MEDIAN" and "RCP8.5MEDIANThis melted dataset looks like this:
>  >
>  >
>  >  >NewestdataUltra
>  >
>  > x variable value L1 1 0.0 y 0. onepctCO2MEDIAN 2
>  > 0.006794447 y 4.90024902 onepctCO2MEDIAN 3 0.014288058 y 0.1607
>  > onepctCO2MEDIAN 4 0.022087920 y 6.63491326 onepctCO2MEDIAN 5 0.030797357
>  > y -1.24295056 onepctCO2MEDIAN 6 0.038451072 y 1.56433744 onepctCO2MEDIAN
>  > 7 0.048087904 y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y 2.20700446
>  > onepctCO2MEDIAN 9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10
>  > 0.080524530 y -1.09135062 onepctCO2MEDIAN 11 0.092760246 y 0.40999399
>  > onepctCO2MEDIAN 12 0.103789609 y -0.12597268 onepctCO2MEDIAN 13
>  > 0.116953168 y -2.41382534 onepctCO2MEDIAN 14 0.129253298 y 7.08902570
>  > onepctCO2MEDIAN 15 0.141710050 y -0.75935388 onepctCO2MEDIAN 16
>  > 0.156002052 y 0.04544160 onepctCO2MEDIAN 17 0.170648172 y -1.5349682

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread Rui Barradas

Hello,

1) In the text you say your dataset is named NewestdataUltra but in the 
ggplot instruction it's Newestdata. One of these is wrong.


2) Is it onepctCO2MEDIAN or RCPonepctCO2MEDIAN?

3) You are filtering out the value in point ) above. So you only plot 3 
regression lines, you don't need 4 colors.



Hope this helps,

Rui Barradas

Às 15:35 de 06/06/19, rain1...@aim.com escreveu:

Hi Rui (and everyone),


Thank you for this! Yes, this did work fine, as I can see my scatter 
plots and regression lines on the same plot, along with the appropriate 
coloring scheme! :)


Just one last question concerning this - I melted other dataframes into 
my new "NewestdataUltra". I now have 4 objects listed in there in this 
order (starting from the top of the list): "onepctCO2MEDIAN", 
"RCP4.5MEDIAN", RCP8.5MEDIAN", and "HistoricalMEDIAN". I tried plotting 
colored scattered plots and regression lines for these in this manner:


ggplot(subset(Newestdata, L1 != 'RCPonepctCO2MEDIAN'), aes(x, value, 
colour = L1)) + geom_point() + scale_color_manual(values =c("green", 
"blue" "red", "black")) + geom_smooth(method = lm, se=FALSE)


However, I received this error:

Error: unexpected string constant in "ggplot(subset(NewestdataUltra, L1 
!= 'RCPonepctCO2MEDIAN'), aes(x, value, colour = L1)) + geom_point() + 
scale_color_manual(values =c("green", "blue" "red""


**//___^

Why would this error appear?  I think that I assigned the colors 
correctly to each of the four objects in question, so why would this occur?


Thank you, once again!

-----Original Message-
From: Rui Barradas 
To: rain1290 ; r-help 
Sent: Thu, Jun 6, 2019 6:52 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

You are confusing some of the values of L1 with L1 itself.
If you just want two of those values in your plot, "onepctCO2MEDIAN" and
"RCP8.5MEDIAN", you need to subset the data filtering out the rows with
L1 == "RCP4.5MEDIAN".

And please forget geom_jitter, it is completely inappropriate for the
type of scatter plot you are trying to graph. You jitter when there is
overplotting, not as a general purpose technique.

Here is one way to do it.


ggplot(subset(NewestdataUltra, L1 != 'RCP4.5MEDIAN'),
         aes(x, value, colour = L1)) +
   geom_point() +
   scale_color_manual(values = c("green", "red")) +
   geom_smooth(method = lm)


Hope this helps,

Rui Barradas

Às 22:37 de 05/06/19, rain1...@aim.com <mailto:rain1...@aim.com> escreveu:
 > Hi Rui (and everyone),
 >
 > Thank you so much for your response! Much appreciated!
 >
 > What if I wanted I create several regression lines and scatter plots in
 > the same ggplot using a "melted" dataset? I would like to create a
 > scatter plot and regression line for both the objects of
 > "onepctCO2MEDIAN" and "RCP8.5MEDIANThis melted dataset looks like this:
 >
 >
 >  >NewestdataUltra
 >
 > x variable value L1 1 0.0 y 0. onepctCO2MEDIAN 2
 > 0.006794447 y 4.90024902 onepctCO2MEDIAN 3 0.014288058 y 0.1607
 > onepctCO2MEDIAN 4 0.022087920 y 6.63491326 onepctCO2MEDIAN 5 0.030797357
 > y -1.24295056 onepctCO2MEDIAN 6 0.038451072 y 1.56433744 onepctCO2MEDIAN
 > 7 0.048087904 y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y 2.20700446
 > onepctCO2MEDIAN 9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10
 > 0.080524530 y -1.09135062 onepctCO2MEDIAN 11 0.092760246 y 0.40999399
 > onepctCO2MEDIAN 12 0.103789609 y -0.12597268 onepctCO2MEDIAN 13
 > 0.116953168 y -2.41382534 onepctCO2MEDIAN 14 0.129253298 y 7.08902570
 > onepctCO2MEDIAN 15 0.141710050 y -0.75935388 onepctCO2MEDIAN 16
 > 0.156002052 y 0.04544160 onepctCO2MEDIAN 17 0.170648172 y -1.53496826
 > onepctCO2MEDIAN 18 0.185318425 y 6.55242014 onepctCO2MEDIAN 19
 > 0.199463055 y -0.83125628 onepctCO2MEDIAN 20 0.213513337 y -2.50991826
 > onepctCO2MEDIAN 21 0.228839271 y 0.13659682 onepctCO2MEDIAN 22
 > 0.246981293 y -1.37198445 onepctCO2MEDIAN 23 0.263012767 y -0.87129883
 > onepctCO2MEDIAN 24 0.278505564 y 0.66325836 onepctCO2MEDIAN 25
 > 0.293658361 y 0.79380363 onepctCO2MEDIAN 26 0.310747266 y 3.48806374
 > onepctCO2MEDIAN 27 0.325990349 y -4.46122081 onepctCO2MEDIAN 28
 > 0.342517540 y 0.08717340 onepctCO2MEDIAN 29 0.362751633 y -1.41715777
 > onepctCO2MEDIAN 30 0.380199537 y -0.99565082 onepctCO2MEDIAN 31
 > 0.394992948 y 0.32155262 onepctCO2MEDIAN 32 0.414373398 y 3.14038657
 > onepctCO2MEDIAN 33 0.430690214 y -0.73760988 onepctCO2MEDIAN 34
 > 0.449738145 y -2.48605407 onepctCO2MEDIAN 35 0.470167458 y -3.42358584
 > onepctCO2MEDIAN 36 0.489019871 y 0.48247475 onepctCO2MEDIAN 37
 > 0.507242471 y -0.97853863 onepctCO2MEDIAN 38 0.524314284 y 8.5359683

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread PIKAL Petr
Hi

Probably missing quotation marks in geom_smooth

geom_smooth(method = "lm", se = FALSE)

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of rain1290--- via R-
> help
> Sent: Thursday, June 6, 2019 4:35 PM
> To: ruipbarra...@sapo.pt; r-help@R-project.org
> Subject: Re: [R] Plotting more than one regression line in ggplot
>
> Hi Rui (and everyone),
> Thank you for this! Yes, this did work fine, as I can see my scatter plots and
> regression lines on the same plot, along with the appropriate coloring scheme!
> :)
> Just one last question concerning this - I melted other dataframes into my new
> "NewestdataUltra". I now have 4 objects listed in there in this order 
> (starting
> from the top of the list): "onepctCO2MEDIAN", "RCP4.5MEDIAN",
> RCP8.5MEDIAN", and "HistoricalMEDIAN". I tried plotting colored scattered
> plots and regression lines for these in this manner:
> ggplot(subset(Newestdata, L1 != 'RCPonepctCO2MEDIAN'), aes(x, value, colour
> = L1)) + geom_point() + scale_color_manual(values =c("green", "blue" "red",
> "black")) + geom_smooth(method = lm, se=FALSE) However, I received this
> error:
> Error: unexpected string constant in "ggplot(subset(NewestdataUltra, L1 !=
> 'RCPonepctCO2MEDIAN'), aes(x, value, colour = L1)) + geom_point() +
> scale_color_manual(values =c("green", "blue" "red""
>
> Why would this error appear?  I think that I assigned the colors correctly to
> each of the four objects in question, so why would this occur?
> Thank you, once again!
> -Original Message-
> From: Rui Barradas 
> To: rain1290 ; r-help 
> Sent: Thu, Jun 6, 2019 6:52 am
> Subject: Re: [R] Plotting more than one regression line in ggplot
>
> Hello,
>
> You are confusing some of the values of L1 with L1 itself.
> If you just want two of those values in your plot, "onepctCO2MEDIAN" and
> "RCP8.5MEDIAN", you need to subset the data filtering out the rows with
> L1 == "RCP4.5MEDIAN".
>
> And please forget geom_jitter, it is completely inappropriate for the
> type of scatter plot you are trying to graph. You jitter when there is
> overplotting, not as a general purpose technique.
>
> Here is one way to do it.
>
>
> ggplot(subset(NewestdataUltra, L1 != 'RCP4.5MEDIAN'),
> aes(x, value, colour = L1)) +
>   geom_point() +
>   scale_color_manual(values = c("green", "red")) +
>   geom_smooth(method = lm)
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 22:37 de 05/06/19, rain1...@aim.com escreveu:
> > Hi Rui (and everyone),
> >
> > Thank you so much for your response! Much appreciated!
> >
> > What if I wanted I create several regression lines and scatter plots in
> > the same ggplot using a "melted" dataset? I would like to create a
> > scatter plot and regression line for both the objects of
> > "onepctCO2MEDIAN" and "RCP8.5MEDIANThis melted dataset looks like
> this:
> >
> >
> >  >NewestdataUltra
> >
> > x variable value L1 1 0.0 y 0. onepctCO2MEDIAN 2
> > 0.006794447 y 4.90024902 onepctCO2MEDIAN 3 0.014288058 y
> 0.1607
> > onepctCO2MEDIAN 4 0.022087920 y 6.63491326 onepctCO2MEDIAN 5
> 0.030797357
> > y -1.24295056 onepctCO2MEDIAN 6 0.038451072 y 1.56433744
> onepctCO2MEDIAN
> > 7 0.048087904 y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y
> 2.20700446
> > onepctCO2MEDIAN 9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10
> > 0.080524530 y -1.09135062 onepctCO2MEDIAN 11 0.092760246 y
> 0.40999399
> > onepctCO2MEDIAN 12 0.103789609 y -0.12597268 onepctCO2MEDIAN 13
> > 0.116953168 y -2.41382534 onepctCO2MEDIAN 14 0.129253298 y
> 7.08902570
> > onepctCO2MEDIAN 15 0.141710050 y -0.75935388 onepctCO2MEDIAN 16
> > 0.156002052 y 0.04544160 onepctCO2MEDIAN 17 0.170648172 y -
> 1.53496826
> > onepctCO2MEDIAN 18 0.185318425 y 6.55242014 onepctCO2MEDIAN 19
> > 0.199463055 y -0.83125628 onepctCO2MEDIAN 20 0.213513337 y -
> 2.50991826
> > onepctCO2MEDIAN 21 0.228839271 y 0.13659682 onepctCO2MEDIAN 22
> > 0.246981293 y -1.37198445 onepctCO2MEDIAN 23 0.263012767 y -
> 0.87129883
> > onepctCO2MEDIAN 24 0.278505564 y 0.66325836 onepctCO2MEDIAN 25
> > 0.293658361 y 0.79380363 onepctCO2MEDIAN 26 0.310747266 y
> 3.48806374
> > onepctCO2MEDIAN 27 0.325990349 y -4.46122081 onepctCO2MEDIAN 28
> > 0.342517540 y 0.08717340 onepctCO2MEDIAN 29 0.362751633 y -
> 1.41715777
> > onepctCO2MEDIAN 30 0.380199537 y -0.99565082 onepctCO2MEDIAN 31
> > 0.3949

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread rain1290--- via R-help
Hi Rui (and everyone),
Thank you for this! Yes, this did work fine, as I can see my scatter plots and 
regression lines on the same plot, along with the appropriate coloring scheme! 
:)
Just one last question concerning this - I melted other dataframes into my new 
"NewestdataUltra". I now have 4 objects listed in there in this order (starting 
from the top of the list): "onepctCO2MEDIAN", "RCP4.5MEDIAN", RCP8.5MEDIAN", 
and "HistoricalMEDIAN". I tried plotting colored scattered plots and regression 
lines for these in this manner:
ggplot(subset(Newestdata, L1 != 'RCPonepctCO2MEDIAN'), aes(x, value, colour = 
L1)) + geom_point() + scale_color_manual(values =c("green", "blue" "red", 
"black")) + geom_smooth(method = lm, se=FALSE) However, I received this error:
Error: unexpected string constant in "ggplot(subset(NewestdataUltra, L1 != 
'RCPonepctCO2MEDIAN'), aes(x, value, colour = L1)) + geom_point() + 
scale_color_manual(values =c("green", "blue" "red""

Why would this error appear?  I think that I assigned the colors correctly to 
each of the four objects in question, so why would this occur? 
Thank you, once again! 
-Original Message-
From: Rui Barradas 
To: rain1290 ; r-help 
Sent: Thu, Jun 6, 2019 6:52 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

You are confusing some of the values of L1 with L1 itself.
If you just want two of those values in your plot, "onepctCO2MEDIAN" and 
"RCP8.5MEDIAN", you need to subset the data filtering out the rows with 
L1 == "RCP4.5MEDIAN".

And please forget geom_jitter, it is completely inappropriate for the 
type of scatter plot you are trying to graph. You jitter when there is 
overplotting, not as a general purpose technique.

Here is one way to do it.


ggplot(subset(NewestdataUltra, L1 != 'RCP4.5MEDIAN'),
        aes(x, value, colour = L1)) +
  geom_point() +
  scale_color_manual(values = c("green", "red")) +
  geom_smooth(method = lm)


Hope this helps,

Rui Barradas

Às 22:37 de 05/06/19, rain1...@aim.com escreveu:
> Hi Rui (and everyone),
> 
> Thank you so much for your response! Much appreciated!
> 
> What if I wanted I create several regression lines and scatter plots in 
> the same ggplot using a "melted" dataset? I would like to create a 
> scatter plot and regression line for both the objects of 
> "onepctCO2MEDIAN" and "RCP8.5MEDIANThis melted dataset looks like this:
> 
> 
>  >NewestdataUltra
> 
> x variable value L1 1 0.0 y 0. onepctCO2MEDIAN 2 
> 0.006794447 y 4.90024902 onepctCO2MEDIAN 3 0.014288058 y 0.1607 
> onepctCO2MEDIAN 4 0.022087920 y 6.63491326 onepctCO2MEDIAN 5 0.030797357 
> y -1.24295056 onepctCO2MEDIAN 6 0.038451072 y 1.56433744 onepctCO2MEDIAN 
> 7 0.048087904 y -2.26590352 onepctCO2MEDIAN 8 0.058677729 y 2.20700446 
> onepctCO2MEDIAN 9 0.069261406 y -2.36770013 onepctCO2MEDIAN 10 
> 0.080524530 y -1.09135062 onepctCO2MEDIAN 11 0.092760246 y 0.40999399 
> onepctCO2MEDIAN 12 0.103789609 y -0.12597268 onepctCO2MEDIAN 13 
> 0.116953168 y -2.41382534 onepctCO2MEDIAN 14 0.129253298 y 7.08902570 
> onepctCO2MEDIAN 15 0.141710050 y -0.75935388 onepctCO2MEDIAN 16 
> 0.156002052 y 0.04544160 onepctCO2MEDIAN 17 0.170648172 y -1.53496826 
> onepctCO2MEDIAN 18 0.185318425 y 6.55242014 onepctCO2MEDIAN 19 
> 0.199463055 y -0.83125628 onepctCO2MEDIAN 20 0.213513337 y -2.50991826 
> onepctCO2MEDIAN 21 0.228839271 y 0.13659682 onepctCO2MEDIAN 22 
> 0.246981293 y -1.37198445 onepctCO2MEDIAN 23 0.263012767 y -0.87129883 
> onepctCO2MEDIAN 24 0.278505564 y 0.66325836 onepctCO2MEDIAN 25 
> 0.293658361 y 0.79380363 onepctCO2MEDIAN 26 0.310747266 y 3.48806374 
> onepctCO2MEDIAN 27 0.325990349 y -4.46122081 onepctCO2MEDIAN 28 
> 0.342517540 y 0.08717340 onepctCO2MEDIAN 29 0.362751633 y -1.41715777 
> onepctCO2MEDIAN 30 0.380199537 y -0.99565082 onepctCO2MEDIAN 31 
> 0.394992948 y 0.32155262 onepctCO2MEDIAN 32 0.414373398 y 3.14038657 
> onepctCO2MEDIAN 33 0.430690214 y -0.73760988 onepctCO2MEDIAN 34 
> 0.449738145 y -2.48605407 onepctCO2MEDIAN 35 0.470167458 y -3.42358584 
> onepctCO2MEDIAN 36 0.489019871 y 0.48247475 onepctCO2MEDIAN 37 
> 0.507242471 y -0.97853863 onepctCO2MEDIAN 38 0.524314284 y 8.53596838 
> onepctCO2MEDIAN 39 0.543750525 y 5.48447420 onepctCO2MEDIAN 40 
> 0.564234197 y 3.21493666 onepctCO2MEDIAN 41 0.583679616 y 3.91689160 
> onepctCO2MEDIAN 42 0.601459444 y 4.49070196 onepctCO2MEDIAN 43 
> 0.619924664 y 6.54104103 onepctCO2MEDIAN 44 0.639932007 y 4.80686500 
> onepctCO2MEDIAN 45 0.661347181 y 8.15101701 onepctCO2MEDIAN 46 
> 0.684117317 y 0.26974132 onepctCO2MEDIAN 47 0.704829752 y -0.18075007 
> onepctCO2MEDIAN 48 0.

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread Rui Barradas
IAN 198 1.041118812 y 0.56107969 RCP4.5MEDIAN 199 
1.050189571 y 3.27941835 RCP4.5MEDIAN 200 1.059380475 y 3.01333588 
RCP4.5MEDIAN 201 1.067877585 y 4.87457336 RCP4.5MEDIAN 202 1.076078766 y 
1.02457895 RCP4.5MEDIAN 203 1.084707357 y 4.49174869 RCP4.5MEDIAN 204 
1.093223180 y 8.24629303 RCP4.5MEDIAN 205 1.101414382 y -0.03364132 
RCP4.5MEDIAN 206 1.108886304 y 9.12509848 RCP4.5MEDIAN 207 1.115482896 y 
1.74254621 RCP4.5MEDIAN 208 1.121856558 y 2.27004536 RCP4.5MEDIAN 209 
1.127809421 y -0.65627179 RCP4.5MEDIAN 210 1.133265961 y 12.02566969 
RCP4.5MEDIAN 211 1.138549712 y -1.04260843 RCP4.5MEDIAN 212 1.143910237 
y -6.47611327 RCP4.5MEDIAN 213 1.149437787 y 8.88410567 RCP4.5MEDIAN 214 
1.154488347 y -4.24916247 RCP4.5MEDIAN 215 1.159872903 y 7.90741918 
RCP4.5MEDIAN 216 1.165477487 y -3.91386711 RCP4.5MEDIAN 217 1.171103424 
y 1.02370701 RCP4.5MEDIAN 218 1.177498256 y -3.71206616 RCP4.5MEDIAN 219 
1.184003888 y -1.05694182 RCP4.5MEDIAN 220 1.190395856 y 1.10501459 
RCP4.5MEDIAN 221 1.197284280 y 2.67668639 RCP4.5MEDIAN 222 1.204590551 y 
2.21693031 RCP4.5MEDIAN 223 1.210807614 y 2.90252830 RCP4.5MEDIAN 224 
1.216470664 y 2.75093766 RCP4.5MEDIAN 225 1.221914148 y -0.73815245 
RCP4.5MEDIAN 226 1.227580480 y 3.58554626 RCP4.5MEDIAN 227 1.233317788 y 
10.89961658 RCP4.5MEDIAN 228 1.238093406 y 3.23374387 RCP4.5MEDIAN 229 
0.466622908 y -1.92366466 RCP8.5MEDIAN 230 0.474211509 y 4.09292949 
RCP8.5MEDIAN 231 0.480383051 y -0.84736312 RCP8.5MEDIAN 232 0.486304903 
y -0.80597889 RCP8.5MEDIAN 233 0.492151615 y -0.50244413 RCP8.5MEDIAN 
234 0.499312643 y 3.07785701 RCP8.5MEDIAN 235 0.508859905 y -6.15175322 
RCP8.5MEDIAN 236 0.518758845 y -0.51590144 RCP8.5MEDIAN 237 0.528675758 
y 3.33135956 RCP8.5MEDIAN 238 0.538928423 y 2.62280891 RCP8.5MEDIAN 239 
0.549621221 y -6.90096009 RCP8.5MEDIAN 240 0.560062840 y -3.45706029 
RCP8.5MEDIAN 241 0.570860791 y 1.36192518 RCP8.5MEDIAN 242 0.581923368 y 
0.34822359 RCP8.5MEDIAN 243 0.592628298 y 3.06882935 RCP8.5MEDIAN 244 
0.604230648 y -3.56142825 RCP8.5MEDIAN 245 0.615975167 y 10.35932554 
RCP8.5MEDIAN 246 0.627448279 y 10.21751629 RCP8.5MEDIAN 247 0.639401050 
y 3.31040335 RCP8.5MEDIAN 248 0.651949591 y -0.53558775 RCP8.5MEDIAN 249 
0.664634427 y 2.66081860 RCP8.5MEDIAN 250 0.677343552 y 3.21379656 
RCP8.5MEDIAN Maybe something like this?


lusher<-ggplot(NewestdataULTRA) + 
geom_jitter(aes(x,value,onepctCO2MEDIAN=L1), colour="green") + 
geom_smooth(aes(x, value, onepctCO2MEDIAN=L1), method=lm) + 
geom_jitter(aes(x, value, RCP8.5MEDIAN=L1), colour="red")**//___^

**//___^
I receive this warning, however:

Warning:Ignoring unknown aesthetics: onepctCO2MEDIAN Warning:Ignoring 
unknown aesthetics: onepctCO2MEDIAN


**//___^
Perhaps I am not assigning the columns properly? Essentially, I just 
want create two scatter plots and two regression lines for these two 
objects.


Once again, any assistance would be greatly appreciated!

-Original Message-
From: Rui Barradas 
To: rain1290 ; r-help ; 
r-sig-geo 

Sent: Wed, Jun 5, 2019 10:52 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

This is pretty basic ggplot.


lm1 <- ggplot(onepctCO2MEDIAN, aes(x, y)) +
   geom_point(colour = 'blue') +
   geom_smooth(method = 'lm')

lm1


If you want to combine several datasets, you will have to have a
variable telling which dataset is which. In the example below, this is
column 'id'.


onepctCO2MEDIAN2 <- onepctCO2MEDIAN
onepctCO2MEDIAN2$y <- jitter(onepctCO2MEDIAN2$y) + 2
onepctCO2MEDIAN$id <- 1
onepctCO2MEDIAN2$id <- 2
df2 <- rbind(onepctCO2MEDIAN, onepctCO2MEDIAN2)

ggplot(df2, aes(x, y, group = id, colour = factor(id))) +
   geom_point() +
   geom_smooth(method = 'lm')


Hope this helps,

Rui Barradas

Às 15:21 de 05/06/19, rain1290--- via R-help escreveu:
 > I am trying to plot, using ggplot, a series of scatter plots with 
regression lines for several datasets. I started with the following 
dataset, "onepectCO2MEDIAN". The data for this dataset is as follows:

 >      onepctCO2MEDIAN
 >      x  y
 >      layer.1   0.0  0.000
 >      layer.2   0.006794447  4.9002490
 >      layer.3   0.014288058  0.1608000
 >      layer.4   0.022087920  6.6349133
 >      layer.5   0.030797357 -1.2429506
 >      layer.6   0.038451072  1.5643374
 >      layer.7   0.048087904 -2.2659035
 >      layer.8   0.058677729  2.2070045
 >      layer.9   0.069261406 -2.3677001
 >      layer.10  0.080524530 -1.0913506
 >      layer.11  0.092760246  0.4099940
 >      layer.12  0.103789609 -0.1259727
 >      layer.13  0.116953168 -2.4138253
 >      layer.14  0.129253298  7.0890257
 >      layer.15  0.141710050 -0.7593539
 >      layer.16  0.156002052  0.0454416
 >      layer.17  0.170648172 -1.5349683
 >      layer.18  0.185318425  6.5524201
 >      layer.19  0.199463055 -0.8312563
 >      lay

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread PIKAL Petr
Hi

It is probably time to consult documentation, including R-Intro. GGplot 
paradigm is that you have set of values (x,y) and factor variable(s) used for 
changing colour, size, plotting character or several other plot items.

so something like
pl <- ggplot(NewestdataULTRA, aes(x=x, y=value, colour=L1))
pl +geom_point()+geom_smooth(method="lm")

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of rain1290--- via R-
> help
> Sent: Wednesday, June 5, 2019 11:37 PM
> To: ruipbarra...@sapo.pt; r-help@R-project.org; r-sig-...@r-project.org
> Subject: Re: [R] Plotting more than one regression line in ggplot
>
> Hi Rui (and everyone),
>
> Thank you so much for your response! Much appreciated!
> What if I wanted I create several regression lines and scatter plots in the 
> same
> ggplot using a "melted" dataset? I would like to create a scatter plot and
> regression line for both the objects of "onepctCO2MEDIAN" and
> "RCP8.5MEDIANThis melted dataset looks like this:
>
> >NewestdataUltra
>  x variable   value  L1
> 1   0.0y  0. onepctCO2MEDIAN
> 2   0.006794447y  4.90024902 onepctCO2MEDIAN
> 3   0.014288058y  0.1607 onepctCO2MEDIAN
> 4   0.022087920y  6.63491326 onepctCO2MEDIAN
> 5   0.030797357y -1.24295056 onepctCO2MEDIAN
> 6   0.038451072y  1.56433744 onepctCO2MEDIAN
> 7   0.048087904y -2.26590352 onepctCO2MEDIAN
> 8   0.058677729y  2.20700446 onepctCO2MEDIAN
> 9   0.069261406y -2.36770013 onepctCO2MEDIAN
> 10  0.080524530y -1.09135062 onepctCO2MEDIAN
> 11  0.092760246y  0.40999399 onepctCO2MEDIAN
> 12  0.103789609y -0.12597268 onepctCO2MEDIAN
> 13  0.116953168y -2.41382534 onepctCO2MEDIAN
> 14  0.129253298y  7.08902570 onepctCO2MEDIAN
> 15  0.141710050y -0.75935388 onepctCO2MEDIAN
> 16  0.156002052y  0.04544160 onepctCO2MEDIAN
> 17  0.170648172y -1.53496826 onepctCO2MEDIAN
> 18  0.185318425y  6.55242014 onepctCO2MEDIAN
> 19  0.199463055y -0.83125628 onepctCO2MEDIAN
> 20  0.213513337y -2.50991826 onepctCO2MEDIAN
> 21  0.228839271y  0.13659682 onepctCO2MEDIAN
> 22  0.246981293y -1.37198445 onepctCO2MEDIAN
> 23  0.263012767y -0.87129883 onepctCO2MEDIAN
> 24  0.278505564y  0.66325836 onepctCO2MEDIAN
> 25  0.293658361y  0.79380363 onepctCO2MEDIAN
> 26  0.310747266y  3.48806374 onepctCO2MEDIAN
> 27  0.325990349y -4.46122081 onepctCO2MEDIAN
> 28  0.342517540y  0.08717340 onepctCO2MEDIAN
> 29  0.362751633y -1.41715777 onepctCO2MEDIAN
> 30  0.380199537y -0.99565082 onepctCO2MEDIAN
> 31  0.394992948y  0.32155262 onepctCO2MEDIAN
> 32  0.414373398y  3.14038657 onepctCO2MEDIAN
> 33  0.430690214y -0.73760988 onepctCO2MEDIAN
> 34  0.449738145y -2.48605407 onepctCO2MEDIAN
> 35  0.470167458y -3.42358584 onepctCO2MEDIAN
> 36  0.489019871y  0.48247475 onepctCO2MEDIAN
> 37  0.507242471y -0.97853863 onepctCO2MEDIAN
> 38  0.524314284y  8.53596838 onepctCO2MEDIAN
> 39  0.543750525y  5.48447420 onepctCO2MEDIAN
> 40  0.564234197y  3.21493666 onepctCO2MEDIAN
> 41  0.583679616y  3.91689160 onepctCO2MEDIAN
> 42  0.601459444y  4.49070196 onepctCO2MEDIAN
> 43  0.619924664y  6.54104103 onepctCO2MEDIAN
> 44  0.639932007y  4.80686500 onepctCO2MEDIAN
> 45  0.661347181y  8.15101701 onepctCO2MEDIAN
> 46  0.684117317y  0.26974132 onepctCO2MEDIAN
> 47  0.704829752y -0.18075007 onepctCO2MEDIAN
> 48  0.725045770y  9.71812491 onepctCO2MEDIAN
> 49  0.745165825y  1.54064657 onepctCO2MEDIAN
> 50  0.765016139y -1.64760409 onepctCO2MEDIAN
> 51  0.783461511y  4.80246029 onepctCO2MEDIAN
> 52  0.806382924y  4.04215160 onepctCO2MEDIAN
> 53  0.829241335y  9.37565122 onepctCO2MEDIAN
> 54  0.849924415y  5.33050497 onepctCO2MEDIAN
> 55  0.871352434y  7.54458026 onepctCO2MEDIAN
> 56  0.893632233y  6.46795471 onepctCO2MEDIAN
> 57  0.916052133y  2.80960651 onepctCO2MEDIAN
> 58  0.938579470y  5.39216613 onepctCO2MEDIAN
> 59  0.959907651y  7.20436888 onepctCO2MEDIAN
> 60  0.981643587y  3.33508065 onepctCO2MEDIAN
> 61  1.004116774y  8.86907070 onepctCO2MEDIAN
> 62  1.028363466y  1.78612989 onepctCO2MEDIAN
> 63  1.054009140y  6.25550382 onepctCO2MEDIAN
> 64  1.072440803y  7.60792365 onepctCO2MEDIAN
> 65  1.094457805y  7.68714831 onepctCO2MEDIAN
> 66  1.123176277y  4.77877639 onepctCO2MEDIAN
> 67 

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread rain1290--- via R-help
8289566y  2.66922982RCP4.5MEDIAN
182 0.917284978y -4.17757196RCP4.5MEDIAN
183 0.926128960y  3.40202916RCP4.5MEDIAN
184 0.934752874y -1.92292218RCP4.5MEDIAN
185 0.943010943y  6.36969150RCP4.5MEDIAN
186 0.950999217y  1.86490308RCP4.5MEDIAN
187 0.958795701y  8.32126161RCP4.5MEDIAN
188 0.966310396y 10.15048356RCP4.5MEDIAN
189 0.973635493y  6.68925964RCP4.5MEDIAN
190 0.980834088y -1.01615369RCP4.5MEDIAN
191 0.987694790y  0.20892853RCP4.5MEDIAN
192 0.994548581y -1.52787222RCP4.5MEDIAN
193 1.001274595y -0.72374597RCP4.5MEDIAN
194 1.007810612y  2.26062309RCP4.5MEDIAN
195 1.014270389y -2.40270340RCP4.5MEDIAN
196 1.022719711y -1.94548262RCP4.5MEDIAN
197 1.032070810y -1.13053235RCP4.5MEDIAN
198 1.041118812y  0.56107969RCP4.5MEDIAN
199 1.050189571y  3.27941835RCP4.5MEDIAN
200 1.059380475y  3.01333588RCP4.5MEDIAN
201 1.067877585y  4.87457336RCP4.5MEDIAN
202 1.076078766y  1.02457895RCP4.5MEDIAN
203 1.084707357y  4.49174869RCP4.5MEDIAN
204 1.093223180y  8.24629303RCP4.5MEDIAN
205 1.101414382y -0.03364132RCP4.5MEDIAN
206 1.108886304y  9.12509848RCP4.5MEDIAN
207 1.115482896y  1.74254621RCP4.5MEDIAN
208 1.121856558y  2.27004536RCP4.5MEDIAN
209 1.127809421y -0.65627179RCP4.5MEDIAN
210 1.133265961y 12.02566969RCP4.5MEDIAN
211 1.138549712y -1.04260843RCP4.5MEDIAN
212 1.143910237y -6.47611327RCP4.5MEDIAN
213 1.149437787y  8.88410567RCP4.5MEDIAN
214 1.154488347y -4.24916247RCP4.5MEDIAN
215 1.159872903y  7.90741918RCP4.5MEDIAN
216 1.165477487y -3.91386711RCP4.5MEDIAN
217 1.171103424y  1.02370701RCP4.5MEDIAN
218 1.177498256y -3.71206616RCP4.5MEDIAN
219 1.184003888y -1.05694182RCP4.5MEDIAN
220 1.190395856y  1.10501459RCP4.5MEDIAN
221 1.197284280y  2.67668639RCP4.5MEDIAN
222 1.204590551y  2.21693031RCP4.5MEDIAN
223 1.210807614y  2.90252830RCP4.5MEDIAN
224 1.216470664y  2.75093766RCP4.5MEDIAN
225 1.221914148y -0.73815245RCP4.5MEDIAN
226 1.227580480y  3.58554626RCP4.5MEDIAN
227 1.233317788y 10.89961658RCP4.5MEDIAN
228 1.238093406y  3.23374387RCP4.5MEDIAN
229 0.466622908y -1.92366466RCP8.5MEDIAN
230 0.474211509y  4.09292949RCP8.5MEDIAN
231 0.480383051y -0.84736312RCP8.5MEDIAN
232 0.486304903y -0.80597889RCP8.5MEDIAN
233 0.492151615y -0.50244413RCP8.5MEDIAN
234 0.499312643y  3.07785701RCP8.5MEDIAN
235 0.508859905y -6.15175322RCP8.5MEDIAN
236 0.518758845y -0.51590144RCP8.5MEDIAN
237 0.528675758y  3.33135956RCP8.5MEDIAN
238 0.538928423y  2.62280891RCP8.5MEDIAN
239 0.549621221y -6.90096009RCP8.5MEDIAN
240 0.560062840y -3.45706029RCP8.5MEDIAN
241 0.570860791y  1.36192518RCP8.5MEDIAN
242 0.581923368y  0.34822359RCP8.5MEDIAN
243 0.592628298y  3.06882935RCP8.5MEDIAN
244 0.604230648y -3.56142825RCP8.5MEDIAN
245 0.615975167y 10.35932554RCP8.5MEDIAN
246 0.627448279y 10.21751629RCP8.5MEDIAN
247 0.639401050y  3.31040335RCP8.5MEDIAN
248 0.651949591y -0.53558775RCP8.5MEDIAN
249 0.664634427y  2.66081860RCP8.5MEDIAN
250 0.677343552y  3.21379656RCP8.5MEDIAN

Maybe something like this?

lusher<-ggplot(NewestdataULTRA) + geom_jitter(aes(x,value,onepctCO2MEDIAN=L1), 
colour="green") + geom_smooth(aes(x, value, onepctCO2MEDIAN=L1), method=lm) + 
geom_jitter(aes(x, value, RCP8.5MEDIAN=L1), colour="red")

I receive this warning, however:
Warning: Ignoring unknown aesthetics: onepctCO2MEDIAN
Warning: Ignoring unknown aesthetics: onepctCO2MEDIAN
Perhaps I am not assigning the columns properly? Essentially, I just want 
create two scatter plots and two regression lines for these two objects. 
Once again, any assistance would be greatly appreciated!
-Original Message-
From: Rui Barradas 
To: rain1290 ; r-help ; r-sig-geo 

Sent: Wed, Jun 5, 2019 10:52 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Hello,

This is pretty basic ggplot.


lm1 <- ggplot(onepctCO2MEDIAN, aes(x, y)) +
  geom_point(colour = 'blue') +
  geom_smooth(method = 'lm')

lm1


If you want to combine several datasets, you will have to have a 
variable telling which dataset is which. In the example below, this is 
column 'id'.


onepctCO2MEDIAN2 <- onepctCO2MEDIAN
onepctCO2MEDIAN2$y <- jitter(onepctCO2MEDIAN2$y) + 2
onepctCO2MEDIAN$id <- 1
onepctCO2MEDIAN2$id <- 2
df2 <- rbind(onepctC

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread David Winsemius



On 6/5/19 9:57 AM, David Winsemius wrote:

On 6/5/19 9:37 AM, rain1...@aim.com wrote:

Hi David (and everyone),

Thank you for your response. I changed the column names to x and y,
but the error/warning persists:

Warning message: Computation failed in `stat_smooth()`: 'what' must be
a function or character string

It is quite baffling as to why this is happening. Why would it work
for the scatter plot and not the regression line?



I'll add that I can reproduce a similar error but not the one you reported:


> lm <- ggplot(onepctCO2MEDIAN) +
+ geom_point(aes(x,y),
+ colour="blue") + geom_smooth(aes(x,y), method=lm)
> lm
Warning message:
Computation failed in `stat_smooth()`:
'what' must be a function or character string

Rerunning after removing the `lm` data object allows successful execution:

 rm(lm)
 ggplot(onepctCO2MEDIAN) +
 geom_point(aes(x,y),
 colour="blue") + geom_smooth(aes(x,y), method=lm)


So it's probably related to the non-standard evaluation where a function 
or a function name can be used and if there is a function name offered, 
the ggplot evaluation model first turns it into a character string and 
then accesses a data object instead of a function.


I'm guessing this would be seen by the package maintainer in due course, 
but I'm copying him.


--

David



Since it works perfectly well on my machine, that means we are now
lacking the required information (from you)  that is generally delivered
via `sessionInfo()`. I get:

R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale:
   [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C LC_TIME=en_US.UTF-8
   [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
LC_MESSAGES=en_US.UTF-8
   [7] LC_PAPER=en_US.UTF-8   LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods base

other attached packages:
[1] ggplot2_3.1.1 zoo_1.8-5

loaded via a namespace (and not attached):
   [1] Rcpp_1.0.1   lattice_0.20-38  withr_2.1.2 assertthat_0.2.1
dplyr_0.8.0.1
   [6] crayon_1.3.4 R6_2.4.0 grid_3.5.2 plyr_1.8.4
gtable_0.3.0
[11] magrittr_1.5 scales_1.0.0 pillar_1.3.1 rlang_0.3.4
lazyeval_0.2.2
[16] rstudioapi_0.10  labeling_0.3 tools_3.5.2 glue_1.3.1
purrr_0.3.2
[21] munsell_0.5.0    yaml_2.2.0   compiler_3.5.2 pkgconfig_2.0.2
colorspace_1.4-1
[26] tidyselect_0.2.5 tibble_2.1.1

I'm also running:

RStudio
Version 1.1.463 – © 2009-2018 RStudio, Inc.


You should now restart a clean session, try again with just the required
packages and report back with full code and data.


Best;

David




-Original Message-
From: David Winsemius 
To: r-help 
Sent: Wed, Jun 5, 2019 12:00 pm
Subject: Re: [R] Plotting more than one regression line in ggplot


On 6/5/19 8:04 AM, rain1290--- via R-help wrote:

Hi Jeff (and everyone),

Thank you for your response and feedback. Yes, I know what you mean

- it was a blind and quick choice to use "lm" as my object name.
Unfortunately, changing the object name to something else does not
eliminate that error/warning message. As a result, the same
error/warning appears when running it. Oddly enough, the scatter plot
is just fine - it's the regression line that struggles to appear.
Could there be another reason for that?

Thanks, again,


TRhe error came because you did not reference the column names
correctly. This succeeds with the data you offered:


ggplot(onepctCO2MEDIAN) +
  geom_jitter(aes(x,y),
  colour="blue") + geom_smooth(aes(x,y), method=lm)


# At some point you changed the column names from
(RCP1pctCO2cumulativeMedian, departurea) to (x,y) , but didn't adjust
your code.


Best;

David.


-Original Message-
From: Jeff Newmiller 
To: rain1290 ; rain1290--- via R-help

; r-help ; r-sig-geo


Sent: Wed, Jun 5, 2019 10:49 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Please read the Posting Guide... posting HTML on a plain text

mailing list really interferes with clear communication.

If you had spent even a small amount of time working with R

tutorials then you would know that "lm" is the name of a very basic,
very important R function. However, you are defining your own object
called "lm" that is very different indeed than the usual "lm"
function. I would guess that in a clean new R workspace where you had
not already run your ggplot function and assigned the result to your
own "lm" object then this code might run. However, once you have run
it once and try to run it again, your "method" argument gives the
wr

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread David Winsemius


On 6/5/19 9:37 AM, rain1...@aim.com wrote:
> Hi David (and everyone),
>
> Thank you for your response. I changed the column names to x and y, 
> but the error/warning persists:
>
> Warning message: Computation failed in `stat_smooth()`: 'what' must be 
> a function or character string
>
> It is quite baffling as to why this is happening. Why would it work 
> for the scatter plot and not the regression line?


Since it works perfectly well on my machine, that means we are now 
lacking the required information (from you)  that is generally delivered 
via `sessionInfo()`. I get:

R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale:
  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C LC_TIME=en_US.UTF-8
  [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 
LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 
LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods base

other attached packages:
[1] ggplot2_3.1.1 zoo_1.8-5

loaded via a namespace (and not attached):
  [1] Rcpp_1.0.1   lattice_0.20-38  withr_2.1.2 assertthat_0.2.1 
dplyr_0.8.0.1
  [6] crayon_1.3.4 R6_2.4.0 grid_3.5.2 plyr_1.8.4   
gtable_0.3.0
[11] magrittr_1.5 scales_1.0.0 pillar_1.3.1 rlang_0.3.4  
lazyeval_0.2.2
[16] rstudioapi_0.10  labeling_0.3 tools_3.5.2 glue_1.3.1   
purrr_0.3.2
[21] munsell_0.5.0    yaml_2.2.0   compiler_3.5.2 pkgconfig_2.0.2  
colorspace_1.4-1
[26] tidyselect_0.2.5 tibble_2.1.1

I'm also running:

RStudio
Version 1.1.463 – © 2009-2018 RStudio, Inc.


You should now restart a clean session, try again with just the required 
packages and report back with full code and data.


Best;

David


>
>
> -Original Message-
> From: David Winsemius 
> To: r-help 
> Sent: Wed, Jun 5, 2019 12:00 pm
> Subject: Re: [R] Plotting more than one regression line in ggplot
>
>
> On 6/5/19 8:04 AM, rain1290--- via R-help wrote:
> > Hi Jeff (and everyone),
> >
> > Thank you for your response and feedback. Yes, I know what you mean 
> - it was a blind and quick choice to use "lm" as my object name. 
> Unfortunately, changing the object name to something else does not 
> eliminate that error/warning message. As a result, the same 
> error/warning appears when running it. Oddly enough, the scatter plot 
> is just fine - it's the regression line that struggles to appear. 
> Could there be another reason for that?
> > Thanks, again,
>
>
> TRhe error came because you did not reference the column names
> correctly. This succeeds with the data you offered:
>
>
> ggplot(onepctCO2MEDIAN) +
>  geom_jitter(aes(x,y),
>  colour="blue") + geom_smooth(aes(x,y), method=lm)
>
>
> # At some point you changed the column names from
> (RCP1pctCO2cumulativeMedian, departurea) to (x,y) , but didn't adjust
> your code.
>
>
> Best;
>
> David.
>
> >
> > -----Original Message-
> > From: Jeff Newmiller 
> > To: rain1290 ; rain1290--- via R-help 
> ; r-help ; r-sig-geo 
> 
> > Sent: Wed, Jun 5, 2019 10:49 am
> > Subject: Re: [R] Plotting more than one regression line in ggplot
> >
> > Please read the Posting Guide... posting HTML on a plain text 
> mailing list really interferes with clear communication.
> >
> > If you had spent even a small amount of time working with R 
> tutorials then you would know that "lm" is the name of a very basic, 
> very important R function. However, you are defining your own object 
> called "lm" that is very different indeed than the usual "lm" 
> function. I would guess that in a clean new R workspace where you had 
> not already run your ggplot function and assigned the result to your 
> own "lm" object then this code might run. However, once you have run 
> it once and try to run it again, your "method" argument gives the 
> wrong version of "lm" to geom_smooth and you confuse it.
> >
> > As the doctor said to the man pounding his own head against the 
> wall, "If it hurts, don't do that." Avoid re-using important object 
> names in R... some common names I see abused this way are df, data, c, 
> t, T, and F. Your choice was unusual, but quite effective at 
> illustrating the problem.
> >
> > On June 5, 2019 7:21:57 AM PDT, rain1290--- via R-help 
>  wrote:
> >> I am trying to plot, using ggplot, a series of scatter plot

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread rain1290--- via R-help
Hi David (and everyone),

Thank you for your response. I changed the column names to x and y, but the 
error/warning persists:
Warning message:
Computation failed in `stat_smooth()`:
'what' must be a function or character string 
It is quite baffling as to why this is happening. Why would it work for the 
scatter plot and not the regression line?

-Original Message-
From: David Winsemius 
To: r-help 
Sent: Wed, Jun 5, 2019 12:00 pm
Subject: Re: [R] Plotting more than one regression line in ggplot


On 6/5/19 8:04 AM, rain1290--- via R-help wrote:
> Hi Jeff (and everyone),
>
> Thank you for your response and feedback. Yes, I know what you mean - it was 
> a blind and quick choice to use "lm" as my object name. Unfortunately, 
> changing the object name to something else does not eliminate that 
> error/warning message. As a result, the same error/warning appears when 
> running it. Oddly enough, the scatter plot is just fine - it's the regression 
> line that struggles to appear. Could there be another reason for that?
> Thanks, again,


TRhe error came because you did not reference the column names 
correctly. This succeeds with the data you offered:


ggplot(onepctCO2MEDIAN) +
  geom_jitter(aes(x,y),
  colour="blue") + geom_smooth(aes(x,y), method=lm)


# At some point you changed the column names from 
(RCP1pctCO2cumulativeMedian, departurea) to (x,y) , but didn't adjust 
your code.


Best;

David.

>
> -Original Message-
> From: Jeff Newmiller 
> To: rain1290 ; rain1290--- via R-help 
> ; r-help ; r-sig-geo 
> 
> Sent: Wed, Jun 5, 2019 10:49 am
> Subject: Re: [R] Plotting more than one regression line in ggplot
>
> Please read the Posting Guide... posting HTML on a plain text mailing list 
> really interferes with clear communication.
>
> If you had spent even a small amount of time working with R tutorials then 
> you would know that "lm" is the name of a very basic, very important R 
> function. However, you are defining your own object called "lm" that is very 
> different indeed than the usual "lm" function. I would guess that in a clean 
> new R workspace where you had not already run your ggplot function and 
> assigned the result to your own "lm" object then this code might run. 
> However, once you have run it once and try to run it again, your "method" 
> argument gives the wrong version of "lm" to geom_smooth and you confuse it.
>
> As the doctor said to the man pounding his own head against the wall, "If it 
> hurts, don't do that." Avoid re-using important object names in R... some 
> common names I see abused this way are df, data, c, t, T, and F. Your choice 
> was unusual, but quite effective at illustrating the problem.
>
> On June 5, 2019 7:21:57 AM PDT, rain1290--- via R-help  
> wrote:
>> I am trying to plot, using ggplot, a series of scatter plots with
>> regression lines for several datasets. I started with the following
>> dataset, "onepectCO2MEDIAN". The data for this dataset is as follows:
>>      onepctCO2MEDIAN
>>      x  y
>>      layer.1   0.0  0.000
>>      layer.2   0.006794447  4.9002490
>>      layer.3   0.014288058  0.1608000
>>      layer.4   0.022087920  6.6349133
>>      layer.5   0.030797357 -1.2429506
>>      layer.6   0.038451072  1.5643374
>>      layer.7   0.048087904 -2.2659035
>>      layer.8   0.058677729  2.2070045
>>      layer.9   0.069261406 -2.3677001
>>      layer.10  0.080524530 -1.0913506
>>      layer.11  0.092760246  0.4099940
>>      layer.12  0.103789609 -0.1259727
>>      layer.13  0.116953168 -2.4138253
>>      layer.14  0.129253298  7.0890257
>>      layer.15  0.141710050 -0.7593539
>>      layer.16  0.156002052  0.0454416
>>      layer.17  0.170648172 -1.5349683
>>      layer.18  0.185318425  6.5524201
>>      layer.19  0.199463055 -0.8312563
>>      layer.20  0.213513337 -2.5099183
>>      layer.21  0.228839271  0.1365968
>>      layer.22  0.246981293 -1.3719845
>>      layer.23  0.263012767 -0.8712988
>>      layer.24  0.278505564  0.6632584
>>      layer.25  0.293658361  0.7938036
>>      layer.26  0.310747266  3.4880637
>>      layer.27  0.325990349 -4.4612208
>>      layer.28  0.342517540  0.0871734
>>      layer.29  0.362751633 -1.4171578
>>      layer.30  0.380199537 -0.9956508
>>      layer.31  0.394992948  0.3215526
>>      layer.32  0.414373398  3.1403866
>>      layer.33  0.430690214 -0.7376099
>>      layer.34  0.449738145 -2.4860541
>>      layer.35  0.470167458 -3.4235858
>>      l

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread David Winsemius



On 6/5/19 8:04 AM, rain1290--- via R-help wrote:

Hi Jeff (and everyone),

Thank you for your response and feedback. Yes, I know what you mean - it was a blind and 
quick choice to use "lm" as my object name. Unfortunately, changing the object 
name to something else does not eliminate that error/warning message. As a result, the 
same error/warning appears when running it. Oddly enough, the scatter plot is just fine - 
it's the regression line that struggles to appear. Could there be another reason for that?
Thanks, again,



TRhe error came because you did not reference the column names 
correctly. This succeeds with the data you offered:



ggplot(onepctCO2MEDIAN) +
 geom_jitter(aes(x,y),
 colour="blue") + geom_smooth(aes(x,y), method=lm)


# At some point you changed the column names from 
(RCP1pctCO2cumulativeMedian, departurea) to (x,y) , but didn't adjust 
your code.



Best;

David.



-Original Message-
From: Jeff Newmiller 
To: rain1290 ; rain1290--- via R-help ; r-help 
; r-sig-geo 
Sent: Wed, Jun 5, 2019 10:49 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Please read the Posting Guide... posting HTML on a plain text mailing list 
really interferes with clear communication.

If you had spent even a small amount of time working with R tutorials then you would know that "lm" is the name of a very basic, 
very important R function. However, you are defining your own object called "lm" that is very different indeed than the usual 
"lm" function. I would guess that in a clean new R workspace where you had not already run your ggplot function and assigned the 
result to your own "lm" object then this code might run. However, once you have run it once and try to run it again, your 
"method" argument gives the wrong version of "lm" to geom_smooth and you confuse it.

As the doctor said to the man pounding his own head against the wall, "If it hurts, 
don't do that." Avoid re-using important object names in R... some common names I 
see abused this way are df, data, c, t, T, and F. Your choice was unusual, but quite 
effective at illustrating the problem.

On June 5, 2019 7:21:57 AM PDT, rain1290--- via R-help  
wrote:

I am trying to plot, using ggplot, a series of scatter plots with
regression lines for several datasets. I started with the following
dataset, "onepectCO2MEDIAN". The data for this dataset is as follows:
     onepctCO2MEDIAN
     x  y
     layer.1   0.0  0.000
     layer.2   0.006794447  4.9002490
     layer.3   0.014288058  0.1608000
     layer.4   0.022087920  6.6349133
     layer.5   0.030797357 -1.2429506
     layer.6   0.038451072  1.5643374
     layer.7   0.048087904 -2.2659035
     layer.8   0.058677729  2.2070045
     layer.9   0.069261406 -2.3677001
     layer.10  0.080524530 -1.0913506
     layer.11  0.092760246  0.4099940
     layer.12  0.103789609 -0.1259727
     layer.13  0.116953168 -2.4138253
     layer.14  0.129253298  7.0890257
     layer.15  0.141710050 -0.7593539
     layer.16  0.156002052  0.0454416
     layer.17  0.170648172 -1.5349683
     layer.18  0.185318425  6.5524201
     layer.19  0.199463055 -0.8312563
     layer.20  0.213513337 -2.5099183
     layer.21  0.228839271  0.1365968
     layer.22  0.246981293 -1.3719845
     layer.23  0.263012767 -0.8712988
     layer.24  0.278505564  0.6632584
     layer.25  0.293658361  0.7938036
     layer.26  0.310747266  3.4880637
     layer.27  0.325990349 -4.4612208
     layer.28  0.342517540  0.0871734
     layer.29  0.362751633 -1.4171578
     layer.30  0.380199537 -0.9956508
     layer.31  0.394992948  0.3215526
     layer.32  0.414373398  3.1403866
     layer.33  0.430690214 -0.7376099
     layer.34  0.449738145 -2.4860541
     layer.35  0.470167458 -3.4235858
     layer.36  0.489019871  0.4824748
     layer.37  0.507242471 -0.9785386
     layer.38  0.524314284  8.5359684
     layer.39  0.543750525  5.4844742
     layer.40  0.564234197  3.2149367
     layer.41  0.583679616  3.9168916
     layer.42  0.601459444  4.4907020
     layer.43  0.619924664  6.5410410
     layer.44  0.639932007  4.8068650
     layer.45  0.661347181  8.1510170
     layer.46  0.684117317  0.2697413
     layer.47  0.704829752 -0.1807501
     layer.48  0.725045770  9.7181249
     layer.49  0.745165825  1.5406466
     layer.50  0.765016139 -1.6476041
     layer.51  0.783461511  4.8024603
     layer.52  0.806382924  4.0421516
     layer.53  0.829241335  9.3756512
     layer.54  0.849924415  5.3305050
     layer.55  0.871352434  7.5445803
     layer.56  0.893632233  6.4679547
     layer.57  0.916052133  2.8096065
     layer.58  0.938579470  5.3921661
     layer.59  0.959907651  7.2043689
     layer.60  0.981643587  3.3350806
     layer.61  1.004116774  8.8690707
     layer.62  1.028363466  1.7861299
     layer.63  1.054009140  6.2555038
     layer.6

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread Rui Barradas

Hello,

And please don't cross post. You have asked both

r-help@r-project.org and
r-sig-...@r-project.org

when you should have asked just one of them.

This is a question for r-help@r-project.org

Rui Barradas

Às 15:52 de 05/06/19, Rui Barradas escreveu:

Hello,

This is pretty basic ggplot.


lm1 <- ggplot(onepctCO2MEDIAN, aes(x, y)) +
   geom_point(colour = 'blue') +
   geom_smooth(method = 'lm')

lm1


If you want to combine several datasets, you will have to have a 
variable telling which dataset is which. In the example below, this is 
column 'id'.



onepctCO2MEDIAN2 <- onepctCO2MEDIAN
onepctCO2MEDIAN2$y <- jitter(onepctCO2MEDIAN2$y) + 2
onepctCO2MEDIAN$id <- 1
onepctCO2MEDIAN2$id <- 2
df2 <- rbind(onepctCO2MEDIAN, onepctCO2MEDIAN2)

ggplot(df2, aes(x, y, group = id, colour = factor(id))) +
   geom_point() +
   geom_smooth(method = 'lm')


Hope this helps,

Rui Barradas

Às 15:21 de 05/06/19, rain1290--- via R-help escreveu:
I am trying to plot, using ggplot, a series of scatter plots with 
regression lines for several datasets. I started with the following 
dataset, "onepectCO2MEDIAN". The data for this dataset is as follows:

 onepctCO2MEDIAN
 x  y
 layer.1   0.0  0.000
 layer.2   0.006794447  4.9002490
 layer.3   0.014288058  0.1608000
 layer.4   0.022087920  6.6349133
 layer.5   0.030797357 -1.2429506
 layer.6   0.038451072  1.5643374
 layer.7   0.048087904 -2.2659035
 layer.8   0.058677729  2.2070045
 layer.9   0.069261406 -2.3677001
 layer.10  0.080524530 -1.0913506
 layer.11  0.092760246  0.4099940
 layer.12  0.103789609 -0.1259727
 layer.13  0.116953168 -2.4138253
 layer.14  0.129253298  7.0890257
 layer.15  0.141710050 -0.7593539
 layer.16  0.156002052  0.0454416
 layer.17  0.170648172 -1.5349683
 layer.18  0.185318425  6.5524201
 layer.19  0.199463055 -0.8312563
 layer.20  0.213513337 -2.5099183
 layer.21  0.228839271  0.1365968
 layer.22  0.246981293 -1.3719845
 layer.23  0.263012767 -0.8712988
 layer.24  0.278505564  0.6632584
 layer.25  0.293658361  0.7938036
 layer.26  0.310747266  3.4880637
 layer.27  0.325990349 -4.4612208
 layer.28  0.342517540  0.0871734
 layer.29  0.362751633 -1.4171578
 layer.30  0.380199537 -0.9956508
 layer.31  0.394992948  0.3215526
 layer.32  0.414373398  3.1403866
 layer.33  0.430690214 -0.7376099
 layer.34  0.449738145 -2.4860541
 layer.35  0.470167458 -3.4235858
 layer.36  0.489019871  0.4824748
 layer.37  0.507242471 -0.9785386
 layer.38  0.524314284  8.5359684
 layer.39  0.543750525  5.4844742
 layer.40  0.564234197  3.2149367
 layer.41  0.583679616  3.9168916
 layer.42  0.601459444  4.4907020
 layer.43  0.619924664  6.5410410
 layer.44  0.639932007  4.8068650
 layer.45  0.661347181  8.1510170
 layer.46  0.684117317  0.2697413
 layer.47  0.704829752 -0.1807501
 layer.48  0.725045770  9.7181249
 layer.49  0.745165825  1.5406466
 layer.50  0.765016139 -1.6476041
 layer.51  0.783461511  4.8024603
 layer.52  0.806382924  4.0421516
 layer.53  0.829241335  9.3756512
 layer.54  0.849924415  5.3305050
 layer.55  0.871352434  7.5445803
 layer.56  0.893632233  6.4679547
 layer.57  0.916052133  2.8096065
 layer.58  0.938579470  5.3921661
 layer.59  0.959907651  7.2043689
 layer.60  0.981643587  3.3350806
 layer.61  1.004116774  8.8690707
 layer.62  1.028363466  1.7861299
 layer.63  1.054009140  6.2555038
 layer.64  1.072440803  7.6079236
 layer.65  1.094457805  7.6871483
 layer.66  1.123176277  4.7787764
 layer.67  1.149430871 12.7110502
 layer.68  1.170912921 -0.7156284
 layer.69  1.196743071  1.6490899
 layer.70  1.218625903  3.0363024
 layer.71  1.241868377  4.2974769
 layer.72  1.267941594  1.9543778
 layer.73  1.290708780  3.9986964
 layer.74  1.31389  4.5179472
 layer.75  1.339045882  0.9337905
 layer.76  1.362803459  3.3050770
 layer.77  1.384450197  3.5422970
 layer.78  1.409720302  5.9973660
 layer.79  1.435851157  0.5081869
 layer.80  1.455592215  7.9661630
 layer.81  1.479495347  9.9460496
 layer.82  1.506051958  3.7908372
 layer.83  1.525728464  2.5735847
 layer.84  1.549362063 10.1404974
 layer.85  1.573440671 13.7408304
 layer.86  1.600278735  0.9335771
 layer.87  1.623879492  9.7588742
 layer.88  1.650029302  1.2769395
 layer.89  1.672362328 13.4970906
 layer.90  1.700221121 10.2087502
 layer.91  1.724793375  1.6811275
 layer.92  1.751070559  6.1178992
 layer.93  1.778022110 -0.1567626
 layer.94  1.803022087  3.8237479
 layer.95  1.830668867  4.4331468
 layer.96  1.855736911  5.9790707
 layer.97  1.882615030 11.3104333
 layer.98  1.909218490  8.2142607
 layer.99  1.938130021 15.3209674
 layer.100 1.963727593

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread rain1290--- via R-help
Hi Jeff (and everyone),

Thank you for your response and feedback. Yes, I know what you mean - it was a 
blind and quick choice to use "lm" as my object name. Unfortunately, changing 
the object name to something else does not eliminate that error/warning 
message. As a result, the same error/warning appears when running it. Oddly 
enough, the scatter plot is just fine - it's the regression line that struggles 
to appear. Could there be another reason for that?
Thanks, again,


-Original Message-
From: Jeff Newmiller 
To: rain1290 ; rain1290--- via R-help ; 
r-help ; r-sig-geo 
Sent: Wed, Jun 5, 2019 10:49 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Please read the Posting Guide... posting HTML on a plain text mailing list 
really interferes with clear communication.

If you had spent even a small amount of time working with R tutorials then you 
would know that "lm" is the name of a very basic, very important R function. 
However, you are defining your own object called "lm" that is very different 
indeed than the usual "lm" function. I would guess that in a clean new R 
workspace where you had not already run your ggplot function and assigned the 
result to your own "lm" object then this code might run. However, once you have 
run it once and try to run it again, your "method" argument gives the wrong 
version of "lm" to geom_smooth and you confuse it.

As the doctor said to the man pounding his own head against the wall, "If it 
hurts, don't do that." Avoid re-using important object names in R... some 
common names I see abused this way are df, data, c, t, T, and F. Your choice 
was unusual, but quite effective at illustrating the problem.

On June 5, 2019 7:21:57 AM PDT, rain1290--- via R-help  
wrote:
>I am trying to plot, using ggplot, a series of scatter plots with
>regression lines for several datasets. I started with the following
>dataset, "onepectCO2MEDIAN". The data for this dataset is as follows:
>    onepctCO2MEDIAN
>    x  y
>    layer.1   0.0  0.000
>    layer.2   0.006794447  4.9002490
>    layer.3   0.014288058  0.1608000
>    layer.4   0.022087920  6.6349133
>    layer.5   0.030797357 -1.2429506
>    layer.6   0.038451072  1.5643374
>    layer.7   0.048087904 -2.2659035
>    layer.8   0.058677729  2.2070045
>    layer.9   0.069261406 -2.3677001
>    layer.10  0.080524530 -1.0913506
>    layer.11  0.092760246  0.4099940
>    layer.12  0.103789609 -0.1259727
>    layer.13  0.116953168 -2.4138253
>    layer.14  0.129253298  7.0890257
>    layer.15  0.141710050 -0.7593539
>    layer.16  0.156002052  0.0454416
>    layer.17  0.170648172 -1.5349683
>    layer.18  0.185318425  6.5524201
>    layer.19  0.199463055 -0.8312563
>    layer.20  0.213513337 -2.5099183
>    layer.21  0.228839271  0.1365968
>    layer.22  0.246981293 -1.3719845
>    layer.23  0.263012767 -0.8712988
>    layer.24  0.278505564  0.6632584
>    layer.25  0.293658361  0.7938036
>    layer.26  0.310747266  3.4880637
>    layer.27  0.325990349 -4.4612208
>    layer.28  0.342517540  0.0871734
>    layer.29  0.362751633 -1.4171578
>    layer.30  0.380199537 -0.9956508
>    layer.31  0.394992948  0.3215526
>    layer.32  0.414373398  3.1403866
>    layer.33  0.430690214 -0.7376099
>    layer.34  0.449738145 -2.4860541
>    layer.35  0.470167458 -3.4235858
>    layer.36  0.489019871  0.4824748
>    layer.37  0.507242471 -0.9785386
>    layer.38  0.524314284  8.5359684
>    layer.39  0.543750525  5.4844742
>    layer.40  0.564234197  3.2149367
>    layer.41  0.583679616  3.9168916 
>    layer.42  0.601459444  4.4907020
>    layer.43  0.619924664  6.5410410
>    layer.44  0.639932007  4.8068650
>    layer.45  0.661347181  8.1510170
>    layer.46  0.684117317  0.2697413
>    layer.47  0.704829752 -0.1807501
>    layer.48  0.725045770  9.7181249
>    layer.49  0.745165825  1.5406466
>    layer.50  0.765016139 -1.6476041
>    layer.51  0.783461511  4.8024603
>    layer.52  0.806382924  4.0421516
>    layer.53  0.829241335  9.3756512
>    layer.54  0.849924415  5.3305050
>    layer.55  0.871352434  7.5445803
>    layer.56  0.893632233  6.4679547
>    layer.57  0.916052133  2.8096065
>    layer.58  0.938579470  5.3921661
>    layer.59  0.959907651  7.2043689
>    layer.60  0.981643587  3.3350806
>    layer.61  1.004116774  8.8690707
>    layer.62  1.028363466  1.7861299
>    layer.63  1.054009140  6.2555038
>    layer.64  1.072440803  7.6079236
>    layer.65  1.094457805  7.6871483
>    layer.66  1.123176277  4.7787764
>    layer.67  1.149430871 12.7110502
>    layer.68  1.170912921 -0.7156284
>    layer.69  1.196743071  1.6490899
>    layer.70  1

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread Rui Barradas

Hello,

This is pretty basic ggplot.


lm1 <- ggplot(onepctCO2MEDIAN, aes(x, y)) +
  geom_point(colour = 'blue') +
  geom_smooth(method = 'lm')

lm1


If you want to combine several datasets, you will have to have a 
variable telling which dataset is which. In the example below, this is 
column 'id'.



onepctCO2MEDIAN2 <- onepctCO2MEDIAN
onepctCO2MEDIAN2$y <- jitter(onepctCO2MEDIAN2$y) + 2
onepctCO2MEDIAN$id <- 1
onepctCO2MEDIAN2$id <- 2
df2 <- rbind(onepctCO2MEDIAN, onepctCO2MEDIAN2)

ggplot(df2, aes(x, y, group = id, colour = factor(id))) +
  geom_point() +
  geom_smooth(method = 'lm')


Hope this helps,

Rui Barradas

Às 15:21 de 05/06/19, rain1290--- via R-help escreveu:

I am trying to plot, using ggplot, a series of scatter plots with regression lines for 
several datasets. I started with the following dataset, "onepectCO2MEDIAN". The 
data for this dataset is as follows:
     onepctCO2MEDIAN
     x  y
     layer.1   0.0  0.000
     layer.2   0.006794447  4.9002490
     layer.3   0.014288058  0.1608000
     layer.4   0.022087920  6.6349133
     layer.5   0.030797357 -1.2429506
     layer.6   0.038451072  1.5643374
     layer.7   0.048087904 -2.2659035
     layer.8   0.058677729  2.2070045
     layer.9   0.069261406 -2.3677001
     layer.10  0.080524530 -1.0913506
     layer.11  0.092760246  0.4099940
     layer.12  0.103789609 -0.1259727
     layer.13  0.116953168 -2.4138253
     layer.14  0.129253298  7.0890257
     layer.15  0.141710050 -0.7593539
     layer.16  0.156002052  0.0454416
     layer.17  0.170648172 -1.5349683
     layer.18  0.185318425  6.5524201
     layer.19  0.199463055 -0.8312563
     layer.20  0.213513337 -2.5099183
     layer.21  0.228839271  0.1365968
     layer.22  0.246981293 -1.3719845
     layer.23  0.263012767 -0.8712988
     layer.24  0.278505564  0.6632584
     layer.25  0.293658361  0.7938036
     layer.26  0.310747266  3.4880637
     layer.27  0.325990349 -4.4612208
     layer.28  0.342517540  0.0871734
     layer.29  0.362751633 -1.4171578
     layer.30  0.380199537 -0.9956508
     layer.31  0.394992948  0.3215526
     layer.32  0.414373398  3.1403866
     layer.33  0.430690214 -0.7376099
     layer.34  0.449738145 -2.4860541
     layer.35  0.470167458 -3.4235858
     layer.36  0.489019871  0.4824748
     layer.37  0.507242471 -0.9785386
     layer.38  0.524314284  8.5359684
     layer.39  0.543750525  5.4844742
     layer.40  0.564234197  3.2149367
     layer.41  0.583679616  3.9168916
     layer.42  0.601459444  4.4907020
     layer.43  0.619924664  6.5410410
     layer.44  0.639932007  4.8068650
     layer.45  0.661347181  8.1510170
     layer.46  0.684117317  0.2697413
     layer.47  0.704829752 -0.1807501
     layer.48  0.725045770  9.7181249
     layer.49  0.745165825  1.5406466
     layer.50  0.765016139 -1.6476041
     layer.51  0.783461511  4.8024603
     layer.52  0.806382924  4.0421516
     layer.53  0.829241335  9.3756512
     layer.54  0.849924415  5.3305050
     layer.55  0.871352434  7.5445803
     layer.56  0.893632233  6.4679547
     layer.57  0.916052133  2.8096065
     layer.58  0.938579470  5.3921661
     layer.59  0.959907651  7.2043689
     layer.60  0.981643587  3.3350806
     layer.61  1.004116774  8.8690707
     layer.62  1.028363466  1.7861299
     layer.63  1.054009140  6.2555038
     layer.64  1.072440803  7.6079236
     layer.65  1.094457805  7.6871483
     layer.66  1.123176277  4.7787764
     layer.67  1.149430871 12.7110502
     layer.68  1.170912921 -0.7156284
     layer.69  1.196743071  1.6490899
     layer.70  1.218625903  3.0363024
     layer.71  1.241868377  4.2974769
     layer.72  1.267941594  1.9543778
     layer.73  1.290708780  3.9986964
     layer.74  1.31389  4.5179472
     layer.75  1.339045882  0.9337905
     layer.76  1.362803459  3.3050770
     layer.77  1.384450197  3.5422970
     layer.78  1.409720302  5.9973660
     layer.79  1.435851157  0.5081869
     layer.80  1.455592215  7.9661630
     layer.81  1.479495347  9.9460496
     layer.82  1.506051958  3.7908372
     layer.83  1.525728464  2.5735847
     layer.84  1.549362063 10.1404974
     layer.85  1.573440671 13.7408304
     layer.86  1.600278735  0.9335771
     layer.87  1.623879492  9.7588742
     layer.88  1.650029302  1.2769395
     layer.89  1.672362328 13.4970906
     layer.90  1.700221121 10.2087502
     layer.91  1.724793375  1.6811275
     layer.92  1.751070559  6.1178992
     layer.93  1.778022110 -0.1567626
     layer.94  1.803022087  3.8237479
     layer.95  1.830668867  4.4331468
     layer.96  1.855736911  5.9790707
     layer.97  1.882615030 11.3104333
     layer.98  1.909218490  8.2142607
     layer.99  1.938130021 15.3209674
     layer.100 1.963727593  5.8178217
     layer.101 1.993271947  9.6004907
     layer.102 2.022548139  3.4063646
     layer.103 2.050679922  4.7375010
     layer.104 2.078064442  3.0133019
     layer.105 2.104113460  5.5659522
     layer.106 2.133597612 12.0346333
     layer.107 2.164026

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread Jeff Newmiller
Please read the Posting Guide... posting HTML on a plain text mailing list 
really interferes with clear communication.

If you had spent even a small amount of time working with R tutorials then you 
would know that "lm" is the name of a very basic, very important R function. 
However, you are defining your own object called "lm" that is very different 
indeed than the usual "lm" function. I would guess that in a clean new R 
workspace where you had not already run your ggplot function and assigned the 
result to your own "lm" object then this code might run. However, once you have 
run it once and try to run it again, your "method" argument gives the wrong 
version of "lm" to geom_smooth and you confuse it.

As the doctor said to the man pounding his own head against the wall, "If it 
hurts, don't do that." Avoid re-using important object names in R... some 
common names I see abused this way are df, data, c, t, T, and F. Your choice 
was unusual, but quite effective at illustrating the problem.

On June 5, 2019 7:21:57 AM PDT, rain1290--- via R-help  
wrote:
>I am trying to plot, using ggplot, a series of scatter plots with
>regression lines for several datasets. I started with the following
>dataset, "onepectCO2MEDIAN". The data for this dataset is as follows:
>    onepctCO2MEDIAN
>    x  y
>    layer.1   0.0  0.000
>    layer.2   0.006794447  4.9002490
>    layer.3   0.014288058  0.1608000
>    layer.4   0.022087920  6.6349133
>    layer.5   0.030797357 -1.2429506
>    layer.6   0.038451072  1.5643374
>    layer.7   0.048087904 -2.2659035
>    layer.8   0.058677729  2.2070045
>    layer.9   0.069261406 -2.3677001
>    layer.10  0.080524530 -1.0913506
>    layer.11  0.092760246  0.4099940
>    layer.12  0.103789609 -0.1259727
>    layer.13  0.116953168 -2.4138253
>    layer.14  0.129253298  7.0890257
>    layer.15  0.141710050 -0.7593539
>    layer.16  0.156002052  0.0454416
>    layer.17  0.170648172 -1.5349683
>    layer.18  0.185318425  6.5524201
>    layer.19  0.199463055 -0.8312563
>    layer.20  0.213513337 -2.5099183
>    layer.21  0.228839271  0.1365968
>    layer.22  0.246981293 -1.3719845
>    layer.23  0.263012767 -0.8712988
>    layer.24  0.278505564  0.6632584
>    layer.25  0.293658361  0.7938036
>    layer.26  0.310747266  3.4880637
>    layer.27  0.325990349 -4.4612208
>    layer.28  0.342517540  0.0871734
>    layer.29  0.362751633 -1.4171578
>    layer.30  0.380199537 -0.9956508
>    layer.31  0.394992948  0.3215526
>    layer.32  0.414373398  3.1403866
>    layer.33  0.430690214 -0.7376099
>    layer.34  0.449738145 -2.4860541
>    layer.35  0.470167458 -3.4235858
>    layer.36  0.489019871  0.4824748
>    layer.37  0.507242471 -0.9785386
>    layer.38  0.524314284  8.5359684
>    layer.39  0.543750525  5.4844742
>    layer.40  0.564234197  3.2149367
>    layer.41  0.583679616  3.9168916 
>    layer.42  0.601459444  4.4907020
>    layer.43  0.619924664  6.5410410
>    layer.44  0.639932007  4.8068650
>    layer.45  0.661347181  8.1510170
>    layer.46  0.684117317  0.2697413
>    layer.47  0.704829752 -0.1807501
>    layer.48  0.725045770  9.7181249
>    layer.49  0.745165825  1.5406466
>    layer.50  0.765016139 -1.6476041
>    layer.51  0.783461511  4.8024603
>    layer.52  0.806382924  4.0421516
>    layer.53  0.829241335  9.3756512
>    layer.54  0.849924415  5.3305050
>    layer.55  0.871352434  7.5445803
>    layer.56  0.893632233  6.4679547
>    layer.57  0.916052133  2.8096065
>    layer.58  0.938579470  5.3921661
>    layer.59  0.959907651  7.2043689
>    layer.60  0.981643587  3.3350806
>    layer.61  1.004116774  8.8690707
>    layer.62  1.028363466  1.7861299
>    layer.63  1.054009140  6.2555038
>    layer.64  1.072440803  7.6079236
>    layer.65  1.094457805  7.6871483
>    layer.66  1.123176277  4.7787764
>    layer.67  1.149430871 12.7110502
>    layer.68  1.170912921 -0.7156284
>    layer.69  1.196743071  1.6490899
>    layer.70  1.218625903  3.0363024
>    layer.71  1.241868377  4.2974769
>    layer.72  1.267941594  1.9543778
>    layer.73  1.290708780  3.9986964
>    layer.74  1.31389  4.5179472
>    layer.75  1.339045882  0.9337905
>    layer.76  1.362803459  3.3050770
>    layer.77  1.384450197  3.5422970
>    layer.78  1.409720302  5.9973660
>    layer.79  1.435851157  0.5081869
>    layer.80  1.455592215  7.9661630
>    layer.81  1.479495347  9.9460496
>    layer.82  1.506051958  3.7908372
>    layer.83  1.525728464  2.5735847
>    layer.84  1.549362063 10.1404974
>    layer.85  1.573440671 13.7408304
>    layer.86  1.600278735  0.9335771
>    layer.87  1.623879492  9.7588742
>    layer.88  1.650029302  1.2769395
>    layer.89  1.672362328 13.4970906
>    layer.90  1.700221121 10.2087502
>    layer.91  1.724793375  1.6811275
>    layer.92  1.751070559  6.1178992
>    layer.93  1.778022110 -0.1567626
>    layer.94  1.803022087  3.8237479
>    layer.95  1.830668867  4.4331468
>    layer.96  1.855736911  5.9790707
>    layer

[R] Plotting more than one regression line in ggplot

2019-06-05 Thread rain1290--- via R-help
I am trying to plot, using ggplot, a series of scatter plots with regression 
lines for several datasets. I started with the following dataset, 
"onepectCO2MEDIAN". The data for this dataset is as follows:
    onepctCO2MEDIAN
    x  y
    layer.1   0.0  0.000
    layer.2   0.006794447  4.9002490
    layer.3   0.014288058  0.1608000
    layer.4   0.022087920  6.6349133
    layer.5   0.030797357 -1.2429506
    layer.6   0.038451072  1.5643374
    layer.7   0.048087904 -2.2659035
    layer.8   0.058677729  2.2070045
    layer.9   0.069261406 -2.3677001
    layer.10  0.080524530 -1.0913506
    layer.11  0.092760246  0.4099940
    layer.12  0.103789609 -0.1259727
    layer.13  0.116953168 -2.4138253
    layer.14  0.129253298  7.0890257
    layer.15  0.141710050 -0.7593539
    layer.16  0.156002052  0.0454416
    layer.17  0.170648172 -1.5349683
    layer.18  0.185318425  6.5524201
    layer.19  0.199463055 -0.8312563
    layer.20  0.213513337 -2.5099183
    layer.21  0.228839271  0.1365968
    layer.22  0.246981293 -1.3719845
    layer.23  0.263012767 -0.8712988
    layer.24  0.278505564  0.6632584
    layer.25  0.293658361  0.7938036
    layer.26  0.310747266  3.4880637
    layer.27  0.325990349 -4.4612208
    layer.28  0.342517540  0.0871734
    layer.29  0.362751633 -1.4171578
    layer.30  0.380199537 -0.9956508
    layer.31  0.394992948  0.3215526
    layer.32  0.414373398  3.1403866
    layer.33  0.430690214 -0.7376099
    layer.34  0.449738145 -2.4860541
    layer.35  0.470167458 -3.4235858
    layer.36  0.489019871  0.4824748
    layer.37  0.507242471 -0.9785386
    layer.38  0.524314284  8.5359684
    layer.39  0.543750525  5.4844742
    layer.40  0.564234197  3.2149367
    layer.41  0.583679616  3.9168916 
    layer.42  0.601459444  4.4907020
    layer.43  0.619924664  6.5410410
    layer.44  0.639932007  4.8068650
    layer.45  0.661347181  8.1510170
    layer.46  0.684117317  0.2697413
    layer.47  0.704829752 -0.1807501
    layer.48  0.725045770  9.7181249
    layer.49  0.745165825  1.5406466
    layer.50  0.765016139 -1.6476041
    layer.51  0.783461511  4.8024603
    layer.52  0.806382924  4.0421516
    layer.53  0.829241335  9.3756512
    layer.54  0.849924415  5.3305050
    layer.55  0.871352434  7.5445803
    layer.56  0.893632233  6.4679547
    layer.57  0.916052133  2.8096065
    layer.58  0.938579470  5.3921661
    layer.59  0.959907651  7.2043689
    layer.60  0.981643587  3.3350806
    layer.61  1.004116774  8.8690707
    layer.62  1.028363466  1.7861299
    layer.63  1.054009140  6.2555038
    layer.64  1.072440803  7.6079236
    layer.65  1.094457805  7.6871483
    layer.66  1.123176277  4.7787764
    layer.67  1.149430871 12.7110502
    layer.68  1.170912921 -0.7156284
    layer.69  1.196743071  1.6490899
    layer.70  1.218625903  3.0363024
    layer.71  1.241868377  4.2974769
    layer.72  1.267941594  1.9543778
    layer.73  1.290708780  3.9986964
    layer.74  1.31389  4.5179472
    layer.75  1.339045882  0.9337905
    layer.76  1.362803459  3.3050770
    layer.77  1.384450197  3.5422970
    layer.78  1.409720302  5.9973660
    layer.79  1.435851157  0.5081869
    layer.80  1.455592215  7.9661630
    layer.81  1.479495347  9.9460496
    layer.82  1.506051958  3.7908372
    layer.83  1.525728464  2.5735847
    layer.84  1.549362063 10.1404974
    layer.85  1.573440671 13.7408304
    layer.86  1.600278735  0.9335771
    layer.87  1.623879492  9.7588742
    layer.88  1.650029302  1.2769395
    layer.89  1.672362328 13.4970906
    layer.90  1.700221121 10.2087502
    layer.91  1.724793375  1.6811275
    layer.92  1.751070559  6.1178992
    layer.93  1.778022110 -0.1567626
    layer.94  1.803022087  3.8237479
    layer.95  1.830668867  4.4331468
    layer.96  1.855736911  5.9790707
    layer.97  1.882615030 11.3104333
    layer.98  1.909218490  8.2142607
    layer.99  1.938130021 15.3209674
    layer.100 1.963727593  5.8178217
    layer.101 1.993271947  9.6004907
    layer.102 2.022548139  3.4063646
    layer.103 2.050679922  4.7375010
    layer.104 2.078064442  3.0133019
    layer.105 2.104113460  5.5659522
    layer.106 2.133597612 12.0346333
    layer.107 2.164026260 -0.4028320
    layer.108 2.194852829 10.5996780
    layer.109 2.224257946  5.4479584
    layer.110 2.252194643  4.7052374
    layer.111 2.277335048 14.0962019
    layer.112 2.304058313  5.7149016
    layer.113 2.330930233  3.7780072
    layer.114 2.357022762  4.4120620
    layer.115 2.386489272  4.1866085
    layer.116 2.417503953  6.9078802
    layer.117 2.448524356  2.7825739
    layer.118 2.478698969  7.6171786
    layer.119 2.510175705 10.2410603
    layer.120 2.539697886  8.1820711
    layer.121 2.567915559  4.8275494
    layer.122 2.597463250 19.1624883
    layer.123 2.627518773 16.0677109
    layer.124 2.658759236 12.5897081
    layer.125 2.692401528  9.2907988
    layer.126 2.721903205  7.4262502
    layer.127 2.753021359  9.3902518
    layer.128 2.786313415 12.6193550