Visualize asct per diagnosis per year

This adds ggplots to visualize the number of ascts per diagnosis per
year in various methods:

* Histogram
* Density plot
* Frequency plot
* Scatter plot
This commit is contained in:
Jens Sauer 2020-11-19 16:12:04 +01:00
parent e0faa24f40
commit 066d6cedf4

View File

@ -16,7 +16,39 @@ sma_hist_asct_year <- function() {
ggplot(data, aes(x = asct_year)) + geom_histogram(binwidth = 1) ggplot(data, aes(x = asct_year)) + geom_histogram(binwidth = 1)
} }
i_dx_year_data <- function() {
return(data.frame(asct_year = secmal$asct_year, dx = secmal$diagnosis))
}
sma_hist_dx_year <- function() {
data <- i_dx_year_data()
ggplot(data, aes(x = asct_year, colour = dx, fill = dx)) +
geom_histogram(binwidth = 1)
}
sma_dens_dx_year <- function() {
data <- i_dx_year_data()
ggplot(data, aes(x = asct_year, colour = dx, fill = dx)) +
geom_density(alpha = 0.5)
}
sma_freq_dx_year <- function() {
data <- i_dx_year_data()
ggplot(data, aes(x = asct_year, colour = dx)) +
geom_freqpoly(binwidth = 1)
}
sma_jitt_dx_year <- function() {
data <- i_dx_year_data()
ggplot(data, aes(x = asct_year, y = dx, colour = dx, fill = dx)) +
geom_jitter(width = 0.4, height = 0.2)
}
sma_plot_file_hist <- function() { sma_plot_file_hist <- function() {
sma_plot_file("hist_asct_age.png", png, sma_hist_asct_age) sma_plot_file("hist_asct_age.png", png, sma_hist_asct_age)
sma_plot_file("hist_asct_year.png", png, sma_hist_asct_year) sma_plot_file("hist_asct_year.png", png, sma_hist_asct_year)
sma_plot_file("dx_year_hist.png", png, sma_hist_dx_year)
sma_plot_file("dx_year_dens.png", png, sma_dens_dx_year)
sma_plot_file("dx_year_freq.png", png, sma_freq_dx_year)
sma_plot_file("dx_year_jitt.png", png, sma_jitt_dx_year)
} }