Advertisement
andstein

frz_plot_andreas

Jul 26th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1.  
  2. library(reshape)
  3.  
  4. master = read.csv('0_Masterdokument_Datenuebersicht_master.csv', header=T)
  5.  
  6. master <- master[master$msr != 'Schweiz',]
  7.  
  8. master$kanton <- factor(master$kanton)
  9. master$typ_fein <- factor(master$typ_fein)
  10. master$typ_grob <- NULL # stimmt nicht
  11. master$sprachregion <- factor(master$sprachregion)
  12.  
  13. # add color, typ_grob code to typ_fein
  14. typgrobcols = data.frame(
  15. c(1:14),
  16. c(
  17. rep(1, 5), # metropolraum
  18. rep(2, 3), # nichtmetropolitane aglo 1
  19. rep(3, 2), # nichtmetropolitane aglo 2
  20. rep(4, 4) # rural
  21. ),
  22. c(
  23. rep(colors()[555], 5), # red, metropolraum
  24. rep(colors()[130], 3), # blau, nichtmetropolitane aglo 1
  25. rep(colors()[150], 2), # braun (gelb), nichtmetropolitane aglo 2
  26. rep(colors()[258], 4) # grün, rural
  27. ),
  28. stringsAsFactors=F)
  29. names(typgrobcols) <- c('typ_fein', 'typ_grob', 'typ_grob_col')
  30.  
  31. master <- merge(master, typgrobcols, by=c('typ_fein'))
  32.  
  33. ## some summary graphics about MS regions
  34.  
  35. plot(c(master$typ_fein), master$bevölkerung, xlab='MS Typologie (klein=städtisch)', xlim=c(14, 1), ylab='Bevölkerung', main='Zusammenhang Bevölkerung / MS Typologie')
  36.  
  37. ## scatterplot grundvers/nichtgrundvers dichte : ungefähr
  38. with(master, plot(grundvers/bevölkerung, nichtgrundvers/bevölkerung, col=typ_grob_col))
  39.  
  40. ## plot ärzteverteilung schweiz
  41.  
  42. labels <- paste(c('Grundversorger ', 'Spezialisten '), round(x/sum(x) * 100), '%', sep='')
  43. pie(x, labels, main='Ärzteverteilung Schweiz')
  44. dev.copy(pdf, 'R/output/aerztevereilung_schweiz.pdf'); dev.off()
  45.  
  46. master <- master[order(master$bevölkerung),]
  47. with(master, barplot((grundvers+nichtgrundvers)/bevölkerung, border='red', density=0))
  48. master <- master[order(-c(master$typ_fein)),]
  49. par(new=T)
  50. with(master, barplot((grundvers+nichtgrundvers)/bevölkerung, border='green', density=0))
  51.  
  52.  
  53. ## boxplot ärzte / typ_grob
  54. doctors <- with(master, data.frame(typ_grob, grundvers/bevölkerung, nichtgrundvers/bevölkerung, typ_grob_col))
  55. names(doctors) <- c('typ_grob', 'grundvers', 'nichtgrundvers', 'typ_grob_col')
  56. doctors <- melt(doctors, id.vars=c('typ_grob', 'typ_grob_col'))
  57. names(doctors) <- c('typ_grob', 'typ_grob_col', 'which', 'dichte')
  58.  
  59. #TODO make sure order typ_grob & typ_grob_colors always matches
  60. #par(mar=c(8,4,1,1))
  61. boxplot(dichte~typ_grob*which, data=doctors,
  62. xaxt='n',
  63. col=unique(master$typ_grob_col[order(master$typ_grob)]),
  64. ylab='Versorgungsdichte [Arzt/Einwohner]',
  65. main='Ärzteverteilung nach MS Regionen Grob Typ')
  66. axis(1, at=c(2.5, 6.5), tck=0, las=0, labels=c('grundvers', 'nichtgrundvers'))
  67.  
  68. dev.copy(pdf, 'R/output/aerztevereilung_typ_grob.pdf'); dev.off()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement