###Vorlesung 25.1. Farbwahl library(vcd) ### sehr gut für Visualisierung von nominale und ordinalen daten ?hsv ?hcl pie(1,col=hsv(h = 0.5, s = 0.5, v = 0.5)) library(colorspace) pie(rep(1, 12), col = sapply(1:12/12, function(x) hsv(h=x,s=1,v=1))) pie(rep(1, 30), col = sapply(1:30/30, function(x) hsv(h=0.5,s=x,v=1))) pie(rep(1, 12), col = sapply(1:12/12, function(x) hsv(h=0.8,s=0.5,v=x))) pie(rep(1, 12), col = sapply((1:12)*30, function(x) hcl(h=x,c=100,l=100))) pie(rep(1, 12), col = sapply((1:12)*100/12, function(x) hcl(h=180,c=x,l=50))) pie(rep(1, 12), col = sapply((1:12)*100/12, function(x) hcl(h=270,c=50,l=x))) ## Verschiedene Varianten ##wheel <- function(col, radius = 1, ...)pie(rep(1, length(col)), col = col, radius = radius, ...) pal <- function(col, border = "light gray") { n <- length(col) plot(0, 0, type="n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, xlab = "", ylab = "") rect(0:(n-1)/n, 0, 1:n/n, 1, col = col, border = border) } pal(diverge_hcl(7)) pal(diverge_hcl(7, h = c(246, 50), c = 96, l = c(65, 90))) pal(diverge_hcl(7, h = c(130, 43), c = 100, l = c(70, 90))) pal(diverge_hcl(7, h = c(180, 70), c = 70, l = c(90, 95))) pal(diverge_hcl(7, h = c(180, 330), c = 59, l = c(75, 95))) pal(diverge_hcl(7, h = c(128, 330), c = 98, l = c(65, 90))) pal(diverge_hcl(7, h = c(255, 330), l = c(40, 90))) pal(diverge_hcl(7, c = 100, l = c(50, 90), power = 1)) pal(rainbow_hcl(7)) data("Arthritis") #Format #A data frame with 84 observations and 5 variables. #ID patient ID. #Treatment factor indicating treatment (Placebo, Treated). #Sex factor indicating sex (Female, Male). #Age age of patient. #Improved ordered factor indicating treatment outcome (None, Some, Marked). art <- xtabs(~ Treatment + Improved, data = Arthritis, subset = Sex == "Female") art mosaic(art, gp = shading_hsv) mosaic(art, gp = shading_max) mosaic(Improved ~ Treatment | Sex, data = Arthritis, zero_size = 0, highlighting_direction = "right") ?mosaic mosaic(HairEyeColor, gp = shading_hcl) require(graphics) # Single Color hist(rnorm(1000), col = hcl(140,c=50)) hist(rnorm(1000), col = hcl(140,c=50,l=)) # The Foley and Van Dam PhD Data. csd <- matrix(c( 4,2,4,6, 4,3,1,4, 4,7,7,1, 0,7,3,2, 4,5,3,2, 5,4,2,2, 3,1,3,0, 4,4,6,7, 1,10,8,7, 1,5,3,2, 1,5,2,1, 4,1,4,3, 0,3,0,6, 2,1,5,5), nrow = 4) csphd <- function(colors) barplot(csd, col = colors, ylim = c(0,30), names = 72:85, xlab = "Year", ylab = "Students", legend = c("Winter", "Spring", "Summer", "Fall"), main = "Computer Science PhD Graduates", las = 1) # The Original (Metaphorical) Colors (Ouch!) csphd(c("blue", "green", "yellow", "orange")) # A Color Tetrad (Maximal Color Differences) csphd(hcl(h = c(30, 120, 210, 300))) # Same, but lighter and less colorful # Turn off automatic correction to make sure # that we have defined real colors. csphd(hcl(h = c(30, 120, 210, 300), c = 20, l = 90, fixup = FALSE)) # Analogous Colors # Good for those with red/green color confusion csphd(hcl(h = seq(60, 240, by = 60))) # Metaphorical Colors csphd(hcl(h = seq(210, 60, length = 4))) # Cool Colors csphd(hcl(h = seq(120, 0, length = 4) + 150)) # Warm Colors csphd(hcl(h = seq(120, 0, length = 4) - 30))