Skip to content

Commit 42029fd

Browse files
committed
revised graphics
1 parent 3a15a66 commit 42029fd

21 files changed

+936
-52
lines changed

01-1-2-3-child-heart-survival-times/01-1-child-heart-survival-x.Rmd

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,23 @@
77

88
Data are shown in Table 1.1 (page 23) and are contained in [01-1-child-heart-survival-x.csv](01-1-child-heart-survival-x.csv). The data were originally presented in the [NCHDA 2012-15 report](https://nicor4.nicor.org.uk/chd/an_paeds.nsf/vwContent/Analysis%20Documents?Opendocument), but are best seen on [childrensheartsurgery.info](http://childrensheartsurgery.info/).
99

10-
```{r figure 1-1}
10+
```{r}
1111
1212
library(ggplot2)
1313
1414
ThirtyDaySurv <-read.csv("01-1-child-heart-survival-x.csv", header=TRUE) # reads data into ThirtyDaySurv data frame
15-
nhosp=length(ThirtyDaySurv$Hospital)
15+
attach(ThirtyDaySurv)
16+
nhosp=length(Hospital)
17+
```
18+
First in R base graphics
19+
```{r}
20+
par(mar=c(5,15,4,2))
21+
barplot(ThirtyDaySurvival,names.arg=Hospital,horiz=T,xlim=c(86,100), xpd=F,las=1, xlab="% surviving 30 days")
22+
```
23+
24+
25+
Now in ggplot2
26+
```{r}
1627
p <- ggplot(ThirtyDaySurv, aes(x=reorder(Hospital,nhosp:1), y= ThirtyDaySurvival, fill=Hospital)) # constructs initial plot object, , starting with top row
1728
p <- p + geom_bar(stat = "identity") # assigns bar chart-type
1829
p <- p + coord_flip(ylim = c(86,100)) # flips to horizontal bars and limits y-axis
@@ -26,4 +37,16 @@ p # draws the plot
2637

2738
_Figure 1.1 Bar-chart of 30-day survival rates for thirteen hospitals. The choice of the start of the horizontal axis, here 86%, can have a crucial effect on the impression given by the graphic. If the axis starts at 0%, all the hospitals will look indistinguishable, whereas if we started at 95% the differences would look misleadingly dramatic._
2839

29-
For other ways of displaying and explaining this data, and more recent results, see [childrensheartsurgery.info](http://childrensheartsurgery.info/).
40+
For other ways of displaying and explaining this data, and more recent results, see [childrensheartsurgery.info](http://childrensheartsurgery.info/), which uses a dot-plot. This may be more appropriate.
41+
42+
```{r figure 1-1}
43+
p <- ggplot(ThirtyDaySurv, aes(x=reorder(Hospital,nhosp:1), y= ThirtyDaySurvival, fill=Hospital)) # constructs initial plot object, , starting with top row
44+
p <- p + geom_dotplot(binaxis="y",stackdir="center",dotsize=2) # assigns dots chart-type
45+
p <- p + coord_flip(ylim = c(86,100)) # flips to horizontal bars and limits y-axis
46+
p <- p + scale_y_continuous(breaks=seq(86, 100, 2)) # assigns breaks every 2 percent
47+
p <- p + theme(legend.position="none") # removes the legend
48+
p <- p + labs(x="", y="% surviving 30 days") # Adds y-axis label
49+
p # draws the plot
50+
```
51+
52+
_Figure 1.1 Bar-chart of 30-day survival rates for thirteen hospitals represented as a dot-plot, in which the non-zero axis is less important as, unlike a bar, it is not directly connected to the data-point._

01-1-2-3-child-heart-survival-times/01-1-child-heart-survival-x.html

Lines changed: 19 additions & 3 deletions
Large diffs are not rendered by default.

01-1-2-3-child-heart-survival-times/01-3-child-heart-proportions-x.Rmd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ library(ggplot2)
1616
df <- read.csv("01-1-child-heart-survival-x.csv", header=TRUE) # reads csv into dataframe, df
1717
df$Percentage = 100*df$Operations/sum(df$Operations)
1818
df$Pos= rank(df$Percentage)
19+
```
20+
First in R base graphics
21+
22+
```{r}
23+
par(mar=c(5,15,4,2))
24+
barplot(df$Percentage,names.arg=df$Hospital,horiz=T, xpd=F,las=1, xlab="Percentage of all operations in 2012-15 \nthat are carried out in each hospital")
25+
26+
```
27+
28+
Now in ggplot2
29+
30+
```{r}
1931
bp <- ggplot(df, aes(x=reorder(Hospital,-Pos), y=Percentage, fill=Hospital)) #sets initial plot object from the dataframe for Hospitals, reordered by Percentage (descending) as the y-values, colour-filled by Hospital
2032
bp <- bp + geom_bar(stat = "identity") + labs(x="Hospital") # makes the plot a bar-chart
2133
bp <- bp + coord_flip() # makes it an horizontal bar chart

01-1-2-3-child-heart-survival-times/01-3-child-heart-proportions-x.html

Lines changed: 7 additions & 2 deletions
Large diffs are not rendered by default.

02-4-reported-partners/02-4-sexual-partners-x.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ p # draw the plot
4949
5050
```
5151

52-
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.
52+
_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._

02-4-reported-partners/02-4-sexual-partners-x.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

02-5-survival-vs-numbers/02-5-child-heart-surgery-x.Rmd

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,32 @@ Data from 2012-2014 were shown in Table 1.1 (page 23) and are contained in [02-5
1111

1212
### Figure 2.5 (page 57) Scatterplots
1313

14-
```{r}
14+
Quickly in qplot
1515

16+
```{r}
1617
library(ggplot2)
1718
# (a) Survival in under-1s, 1991-1995
1819
child.1991 <- read.csv("02-5-child-heart-surgery-1991-x.csv") # read data into dataframe
20+
attach(child.1991)
21+
qplot(Operations,100*Survivors/Operations,xlim = c(0,700),ylim=c(70,100),ylab = "% 30-day survival", label = Hospital, geom=c("point", "text"),hjust=1, vjust=-1,size=2, main = "(a) Survival in under-1s, 1991-1995") + theme(legend.position="none")
1922
23+
# (a) Survival in under-1s, 1991-1995
24+
#(b) Survival for all children, 2012-2015
25+
child.2012 <- read.csv("02-5-child-heart-surgery-2012-x.csv") # read data into dataframe all
26+
attach(child.2012)
27+
qplot(Operations,100*Survivors/Operations,xlim = c(0,2000),ylim=c(95,100),ylab = "% 30-day survival", label = Hospital, geom=c("point", "text"),hjust=1, vjust=-1,size=2, main = "(b) Survival for all children, 2012-2015") + theme(legend.position="none")
28+
29+
30+
```
31+
32+
```{r}
2033
p <- ggplot(child.1991, aes(x=Operations, y=100*Survivors/Operations, col=Hospital)) #defines plot axis data fields and colour legend data field
2134
p <- p + geom_point(aes(size=1.5)) # defines scatter-type plot
2235
p <- p + expand_limits(x = c(0,700),y=c(70,100))
2336
p <- p + scale_size_continuous(name = "Size", guide = FALSE) # turns off otherwise added size legend
2437
p <- p + labs(x="Number of operations", y = "% 30-day survival", title="(a) Survival in under-1s, 1991-1995") # Adds title, subtitle, and caption
25-
p <- p + theme(plot.caption=element_text(hjust = 0.5)) # centre justifies the caption
2638
p
39+
2740
#(b) Survival for all children, 2012-2015
2841
child.2012 <- read.csv("02-5-child-heart-surgery-2012-x.csv") # read data into dataframe all
2942
q <- ggplot(child.2012, aes(x=Operations, y=100*Survivors/Operations,col=Hospital)) #defines plot axis data fields and colour legend data field
@@ -35,8 +48,8 @@ q
3548
3649
```
3750

38-
Figure 2.5
39-
Scatter-plots of survival rates against number of operations in child heart surgery. For (a) 1991-1995, the Pearson correlation is 0.59 and the rank correlation is 0.85, for (b) 2012-2015, the Pearson correlation is 0.17 and the rank correlation is -0:03.
51+
_Figure 2.5
52+
Scatter-plots of survival rates against number of operations in child heart surgery. For (a) 1991-1995, the Pearson correlation is 0.59 and the rank correlation is 0.85, for (b) 2012-2015, the Pearson correlation is 0.17 and the rank correlation is -0:03._
4053

4154

4255
### Correlations in (a) 1991-1995 data

02-5-survival-vs-numbers/02-5-child-heart-surgery-x.html

Lines changed: 35 additions & 7 deletions
Large diffs are not rendered by default.

02-6-zero-correlations/02-6-zero-correlations-x.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ p
2626
2727
```
2828

29-
Figure 2.6 Two sets of (fictitious) data-points for which the Pearson correlation coefficients are both 0. This clearly does not mean there is no relationship between the two variables being plotted.
29+
_Figure 2.6 Two sets of (fictitious) data-points for which the Pearson correlation coefficients are both 0. This clearly does not mean there is no relationship between the two variables being plotted._

02-6-zero-correlations/02-6-zero-correlations-x.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)