series of densities

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

series of densities

tring
Dear friends
I'm trying to plot in silico derived values of 3 types of
buffer-capacities  over pH values and want densities of the three types
together at each pH with the pH values on the abscissa.

I have generated some data

set.seed(2345)
pHs <- c(7.2,7.4,7.6)
pH <- rep(pHs,each=30)
BC <- rep(rep(c(20,10,10),each=10),3)+rnorm(90,0,5)
type <- rep(rep(c("TOT","NC","CA"),each=10),3)

ddd <- data.frame(pH,BC,type)

GG <- ggplot()
for (i in 1:3) {
   dd <- ddd[ddd$pH==pHs[i],]
   GG <- GG + geom_density(data=dd,aes(x=BC,fill=type),alpha=0.1)
}
GG

but here I only get all pH values  plotted together whereas I want 3
series in the vertical direction at the three pH values.

I wonder how this could be done?

All best wishes

Troels Ring, MD
Aalborg, Denmark

PS: Windows 10,

R version 4.0.5 (2021-03-31

______________________________________________
[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.
Reply | Threaded
Open this post in threaded view
|

Re: series of densities

David Winsemius

On 5/17/21 7:44 AM, Troels Ring wrote:

> Dear friends
> I'm trying to plot in silico derived values of 3 types of
> buffer-capacities  over pH values and want densities of the three
> types together at each pH with the pH values on the abscissa.
>
> I have generated some data
>
> set.seed(2345)
> pHs <- c(7.2,7.4,7.6)
> pH <- rep(pHs,each=30)
> BC <- rep(rep(c(20,10,10),each=10),3)+rnorm(90,0,5)
> type <- rep(rep(c("TOT","NC","CA"),each=10),3)
>
> ddd <- data.frame(pH,BC,type)
>
> GG <- ggplot()
> for (i in 1:3) {
>   dd <- ddd[ddd$pH==pHs[i],]
>   GG <- GG + geom_density(data=dd,aes(x=BC,fill=type),alpha=0.1)
> }
> GG
>
> but here I only get all pH values  plotted together whereas I want 3
> series in the vertical direction at the three pH values.


Are you perhaps hoping for means of grouped values connected by lines?


Of perhaps a bee-swarm type plot? there are quite a few overlapping points.


-- --

David.

>
> I wonder how this could be done?
>
> All best wishes
>
> Troels Ring, MD
> Aalborg, Denmark
>
> PS: Windows 10,
>
> R version 4.0.5 (2021-03-31
>
> ______________________________________________
> [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-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: series of densities

David Winsemius
In reply to this post by tring

On 5/17/21 7:44 AM, Troels Ring wrote:

> Dear friends
> I'm trying to plot in silico derived values of 3 types of
> buffer-capacities  over pH values and want densities of the three
> types together at each pH with the pH values on the abscissa.
>
> I have generated some data
>
> set.seed(2345)
> pHs <- c(7.2,7.4,7.6)
> pH <- rep(pHs,each=30)
> BC <- rep(rep(c(20,10,10),each=10),3)+rnorm(90,0,5)
> type <- rep(rep(c("TOT","NC","CA"),each=10),3)
>
> ddd <- data.frame(pH,BC,type)
>
> GG <- ggplot()
> for (i in 1:3) {
>   dd <- ddd[ddd$pH==pHs[i],]
>   GG <- GG + geom_density(data=dd,aes(x=BC,fill=type),alpha=0.1)
> }
> GG
>
> but here I only get all pH values  plotted together whereas I want 3
> series in the vertical direction at the three pH values.
>
> I wonder how this could be done?

Here are two different displays of the data. I haven't figured out what
was intended by the request for " 3 series in the vertical direction at
the three pH values".

library(ggplot2)

#violin plots are density-like

ggplot( data=ddd, aes(x=pH, y=BC,group=interaction(type,pH),
col=type))+geom_violin()

#boxplots are summary methods

ggplot( data=ddd, aes(x=pH, y=BC,group=interaction(type,pH),
col=type))+geom_boxplot()


>
> All best wishes
>
> Troels Ring, MD
> Aalborg, Denmark
>
> PS: Windows 10,
>
> R version 4.0.5 (2021-03-31
>
> ______________________________________________
> [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-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: series of densities

R help mailing list-2
In reply to this post by tring
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: series of densities

tring
In reply to this post by tring
Thanks a lot to David and William - I think

ggplot( data=ddd, aes(x=pH, y=BC,group=interaction(type,pH),
col=type))+geom_boxplot()

was very helpful!

All best

Troels

Den 18-05-2021 kl. 02:27 skrev David Winsemius:
> ggplot( data=ddd, aes(x=pH, y=BC,group=interaction(type,pH),
> col=type))+geom_boxplot()

______________________________________________
[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.