|
|
Hello
is it possible to color the data of a dataframe according to the
values of one column?
I have a dataframe that OI have subdivided into X and Y, with a third
Z with the sample number. I would like to plot Y~X but coloring using
Z. But I would like to use base R and not lines.
Is that possible?
Thank you
```
d <- 2
K <- 10^13
A1_0 <- 1
A2_0 <- 100
A3_0 <- 500
A4_0 <- 10000
PCR <- function(initCopy, dupRate, Carry) {
ROI_T = initCopy
A = array()
for (i in 1:45) {
ROI_TplusOne <- ROI_T * dupRate * (1 - ROI_T/Carry)
A[i] <- ROI_TplusOne
ROI_T <- ROI_TplusOne
}
return(A)
}
A1 <- PCR(A1_0, d, K)
A2 <- PCR(A2_0, d, K)
A3 <- PCR(A3_0, d, K)
A4 <- PCR(A4_0, d, K)
# store results and plot
Z <- c(rep(1, 45), rep(2, 45), rep(3, 45), rep(4, 45))
X = rep(1:45,4)
Y = c(A1, A2, A3, A4)
ROI <- data.frame(Z, X, Y)
plot(Y ~ X, data = ROI, type = "l", lwd = 3)
```
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
|
|
1. lines() *is* base R.
2. See the col argument of ?plot.default.
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Sun, Jan 24, 2021 at 6:48 AM Luigi Marongiu < [hidden email]>
wrote:
> Hello
> is it possible to color the data of a dataframe according to the
> values of one column?
> I have a dataframe that OI have subdivided into X and Y, with a third
> Z with the sample number. I would like to plot Y~X but coloring using
> Z. But I would like to use base R and not lines.
> Is that possible?
> Thank you
>
> ```
> d <- 2
> K <- 10^13
> A1_0 <- 1
> A2_0 <- 100
> A3_0 <- 500
> A4_0 <- 10000
> PCR <- function(initCopy, dupRate, Carry) {
> ROI_T = initCopy
> A = array()
> for (i in 1:45) {
> ROI_TplusOne <- ROI_T * dupRate * (1 - ROI_T/Carry)
> A[i] <- ROI_TplusOne
> ROI_T <- ROI_TplusOne
> }
> return(A)
> }
> A1 <- PCR(A1_0, d, K)
> A2 <- PCR(A2_0, d, K)
> A3 <- PCR(A3_0, d, K)
> A4 <- PCR(A4_0, d, K)
> # store results and plot
> Z <- c(rep(1, 45), rep(2, 45), rep(3, 45), rep(4, 45))
> X = rep(1:45,4)
> Y = c(A1, A2, A3, A4)
> ROI <- data.frame(Z, X, Y)
> plot(Y ~ X, data = ROI, type = "l", lwd = 3)
> ```
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
|
|
No. I was wrong. ?plot.default says only one line color (the first) will be
used. So it appears that you need to use lines().
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Sun, Jan 24, 2021 at 8:41 AM Bert Gunter < [hidden email]> wrote:
> 1. lines() *is* base R.
>
> 2. See the col argument of ?plot.default.
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sun, Jan 24, 2021 at 6:48 AM Luigi Marongiu < [hidden email]>
> wrote:
>
>> Hello
>> is it possible to color the data of a dataframe according to the
>> values of one column?
>> I have a dataframe that OI have subdivided into X and Y, with a third
>> Z with the sample number. I would like to plot Y~X but coloring using
>> Z. But I would like to use base R and not lines.
>> Is that possible?
>> Thank you
>>
>> ```
>> d <- 2
>> K <- 10^13
>> A1_0 <- 1
>> A2_0 <- 100
>> A3_0 <- 500
>> A4_0 <- 10000
>> PCR <- function(initCopy, dupRate, Carry) {
>> ROI_T = initCopy
>> A = array()
>> for (i in 1:45) {
>> ROI_TplusOne <- ROI_T * dupRate * (1 - ROI_T/Carry)
>> A[i] <- ROI_TplusOne
>> ROI_T <- ROI_TplusOne
>> }
>> return(A)
>> }
>> A1 <- PCR(A1_0, d, K)
>> A2 <- PCR(A2_0, d, K)
>> A3 <- PCR(A3_0, d, K)
>> A4 <- PCR(A4_0, d, K)
>> # store results and plot
>> Z <- c(rep(1, 45), rep(2, 45), rep(3, 45), rep(4, 45))
>> X = rep(1:45,4)
>> Y = c(A1, A2, A3, A4)
>> ROI <- data.frame(Z, X, Y)
>> plot(Y ~ X, data = ROI, type = "l", lwd = 3)
>> ```
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html>> and provide commented, minimal, self-contained, reproducible code.
>>
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
|
|
Hello,
Base R:
colrs <- rainbow(length(unique(ROI$Z)))
roi_wide <- reshape(ROI, v.names = "Y", timevar = "Z", idvar = "X",
direction = "wide")
matplot(roi_wide, type = "l", lwd = 3, lty = "solid", col = colrs)
Hope this helps,
Rui Barradas
Às 14:48 de 24/01/21, Luigi Marongiu escreveu:
> Hello
> is it possible to color the data of a dataframe according to the
> values of one column?
> I have a dataframe that OI have subdivided into X and Y, with a third
> Z with the sample number. I would like to plot Y~X but coloring using
> Z. But I would like to use base R and not lines.
> Is that possible?
> Thank you
>
> ```
> d <- 2
> K <- 10^13
> A1_0 <- 1
> A2_0 <- 100
> A3_0 <- 500
> A4_0 <- 10000
> PCR <- function(initCopy, dupRate, Carry) {
> ROI_T = initCopy
> A = array()
> for (i in 1:45) {
> ROI_TplusOne <- ROI_T * dupRate * (1 - ROI_T/Carry)
> A[i] <- ROI_TplusOne
> ROI_T <- ROI_TplusOne
> }
> return(A)
> }
> A1 <- PCR(A1_0, d, K)
> A2 <- PCR(A2_0, d, K)
> A3 <- PCR(A3_0, d, K)
> A4 <- PCR(A4_0, d, K)
> # store results and plot
> Z <- c(rep(1, 45), rep(2, 45), rep(3, 45), rep(4, 45))
> X = rep(1:45,4)
> Y = c(A1, A2, A3, A4)
> ROI <- data.frame(Z, X, Y)
> plot(Y ~ X, data = ROI, type = "l", lwd = 3)
> ```
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
>
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
|
|
I did not know about matplot, but it did the work. using lines is my
default procedure but it can be time-consuming. Thank you all.
On Sun, Jan 24, 2021 at 6:45 PM Rui Barradas < [hidden email]> wrote:
>
> Hello,
>
> Base R:
>
> colrs <- rainbow(length(unique(ROI$Z)))
> roi_wide <- reshape(ROI, v.names = "Y", timevar = "Z", idvar = "X",
> direction = "wide")
> matplot(roi_wide, type = "l", lwd = 3, lty = "solid", col = colrs)
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 14:48 de 24/01/21, Luigi Marongiu escreveu:
> > Hello
> > is it possible to color the data of a dataframe according to the
> > values of one column?
> > I have a dataframe that OI have subdivided into X and Y, with a third
> > Z with the sample number. I would like to plot Y~X but coloring using
> > Z. But I would like to use base R and not lines.
> > Is that possible?
> > Thank you
> >
> > ```
> > d <- 2
> > K <- 10^13
> > A1_0 <- 1
> > A2_0 <- 100
> > A3_0 <- 500
> > A4_0 <- 10000
> > PCR <- function(initCopy, dupRate, Carry) {
> > ROI_T = initCopy
> > A = array()
> > for (i in 1:45) {
> > ROI_TplusOne <- ROI_T * dupRate * (1 - ROI_T/Carry)
> > A[i] <- ROI_TplusOne
> > ROI_T <- ROI_TplusOne
> > }
> > return(A)
> > }
> > A1 <- PCR(A1_0, d, K)
> > A2 <- PCR(A2_0, d, K)
> > A3 <- PCR(A3_0, d, K)
> > A4 <- PCR(A4_0, d, K)
> > # store results and plot
> > Z <- c(rep(1, 45), rep(2, 45), rep(3, 45), rep(4, 45))
> > X = rep(1:45,4)
> > Y = c(A1, A2, A3, A4)
> > ROI <- data.frame(Z, X, Y)
> > plot(Y ~ X, data = ROI, type = "l", lwd = 3)
> > ```
> >
> > ______________________________________________
> > [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code.
> >
--
Best regards,
Luigi
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
|
|