Data are contained in 02-4-sexual-partners-counts-x.csv, and comprise the distribution of the reported lifetime number of opposite-sex partners for men and women aged 35-44. The data are from the Natsal-3 survey reported in C.H. Mercer et al., ‘Changes in Sexual Attitudes and Lifestyles in Britain through the Life Course and Over Time: Findings from the National Surveys of Sexual Attitudes and Lifestyles (Natsal)’, 2013. These raw data, kindly provided by Natsal, correspond to a nominal total of 796 men and 1,193 women, rather than the 806 and 1,215 reported in Mercer et al (2013). The summary statistics do not match those in Table 2.2 (page 53), which come from Tables 2 and 3 of Mercer et al (2013), and are based on data that has been reweighted to allow for the stratified design of the survey.
For a vivid examination of sex statistics, see Sex by Numbers, 2015 .
library(ggplot2)
partner.counts <-read.csv("02-4-sexual-partners-counts-x.csv", header=TRUE) # reads data into data frame
attach(partner.counts)
Men.data=rep(NumPartners,MenCount)
summary(Men.data)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00 4.00 8.00 16.98 20.00 501.00
sd(Men.data)
## [1] 37.80737
range(Men.data)
## [1] 0 501
sum(MenCount)
## [1] 796
Women.data=rep(NumPartners,WomenCount)
summary(Women.data)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00 2.00 5.00 8.23 10.00 550.00
sd(Women.data)
## [1] 17.95505
range(Women.data)
## [1] 0 550
sum(WomenCount)
## [1] 1193
# create data frame with Gender as factor
Ncats=length(NumPartners)
partners = data.frame( NumPartners2=c(NumPartners,NumPartners), Percent=c(MenPercent,WomenPercent), Gender=c(rep("M",Ncats),rep("F",Ncats)) )
p <- ggplot(partners, aes(x=NumPartners2)) # constructs initial plot object, p
p <- p + geom_bar(aes(y=Percent,fill=Gender),stat = "identity",position="dodge") # assigns bar-chart type with side by side (dodged) bars
p <- p + geom_text(aes(x = 20, y = 12, label = "Women 35-44", color = "Female", hjust=0)) # our custom legend
p <- p + geom_text(aes(x = 20, y = 11, label = "Men 35-44", color = "Male", hjust=0)) # our custom legend
p <- p + scale_x_continuous(breaks = c(0,5,10,15,20,25,30,35,40,45,50), limits=c(0,50)) # desired x-axis value labels
p <- p + scale_y_continuous(breaks = c(0,2,4,6,8,10,12,14,16,18)) # desired y-axis value labels
p <- p + scale_colour_brewer(palette = "Set1") # sets the colour palette
p <- p + theme(legend.position="none") # removes the default legend
p <- p + labs(x="Reported number of lifetime opposite-sex partners", y="Percentage") # Adds axis labels
p # draw the plot
## Warning: Removed 174 rows containing missing values (geom_bar).
Figure 2.4 Data provided by Natsal-3 based on interviews between 2010 and 2012. The series have been truncated at 50 for reasons of space - the totals go up to 500 for both men and women. Note the clear use of round numbers for ten or more partners, and the tendency for men to report more partners than women.