|
| 1 | +# Clear aspect ratio test - what SHOULD we see? |
| 2 | + |
| 3 | +library(lattice) |
| 4 | +library(ggplot2) |
| 5 | + |
| 6 | +# Simple data: 3 columns x 1 row = 3 tiles in a horizontal line |
| 7 | +test_data <- data.frame( |
| 8 | + x = c(1, 2, 3), |
| 9 | + y = c(1, 1, 1), |
| 10 | + value = c(1, 2, 3) |
| 11 | +) |
| 12 | + |
| 13 | +cat("Data: 3 tiles in a row (3 units wide, 1 unit tall)\n\n") |
| 14 | + |
| 15 | +# ----------------------------------------------------------------------------- |
| 16 | +# Test 1: aspect = 1 (SQUARE CELLS) |
| 17 | +# ----------------------------------------------------------------------------- |
| 18 | +cat("=== Test 1: aspect = 1 ===\n") |
| 19 | +cat("EXPECTED: Each individual cell/tile should be SQUARE\n") |
| 20 | +cat("Since we have 3 tiles in a row, the overall plot should be 3x wider than tall\n\n") |
| 21 | + |
| 22 | +print(levelplot(value ~ x*y, data=test_data, |
| 23 | + aspect=1, |
| 24 | + main="Lattice: aspect=1 (cells should be square)", |
| 25 | + scales=list(draw=TRUE), |
| 26 | + colorkey=FALSE)) |
| 27 | + |
| 28 | +print(ggplot(test_data, aes(x=x, y=y, fill=value)) + |
| 29 | + geom_tile() + |
| 30 | + coord_fixed(ratio=1) + |
| 31 | + ggtitle("ggplot: ratio=1 (cells should be square)") + |
| 32 | + theme_minimal() + |
| 33 | + theme(aspect.ratio=NULL)) |
| 34 | + |
| 35 | +readline("Press Enter for next test...") |
| 36 | + |
| 37 | +# ----------------------------------------------------------------------------- |
| 38 | +# Test 2: aspect = 1.5 (CELLS TALLER THAN WIDE) |
| 39 | +# ----------------------------------------------------------------------------- |
| 40 | +cat("\n=== Test 2: aspect = 1.5 ===\n") |
| 41 | +cat("EXPECTED: Each cell should be 1.5x TALLER than wide\n") |
| 42 | +cat("If a cell is 10cm wide, it should be 15cm tall\n\n") |
| 43 | + |
| 44 | +print(levelplot(value ~ x*y, data=test_data, |
| 45 | + aspect=1.5, |
| 46 | + main="Lattice: aspect=1.5 (cells 1.5x taller than wide)", |
| 47 | + scales=list(draw=TRUE), |
| 48 | + colorkey=FALSE)) |
| 49 | + |
| 50 | +print(ggplot(test_data, aes(x=x, y=y, fill=value)) + |
| 51 | + geom_tile() + |
| 52 | + coord_fixed(ratio=1.5) + |
| 53 | + ggtitle("ggplot: ratio=1.5 (cells 1.5x taller than wide)") + |
| 54 | + theme_minimal() + |
| 55 | + theme(aspect.ratio=NULL)) |
| 56 | + |
| 57 | +readline("Press Enter for next test...") |
| 58 | + |
| 59 | +# ----------------------------------------------------------------------------- |
| 60 | +# Test 3: aspect = 2 (CELLS MUCH TALLER) |
| 61 | +# ----------------------------------------------------------------------------- |
| 62 | +cat("\n=== Test 3: aspect = 2 ===\n") |
| 63 | +cat("EXPECTED: Each cell should be 2x TALLER than wide\n") |
| 64 | +cat("If a cell is 10cm wide, it should be 20cm tall\n\n") |
| 65 | + |
| 66 | +print(levelplot(value ~ x*y, data=test_data, |
| 67 | + aspect=2, |
| 68 | + main="Lattice: aspect=2 (cells 2x taller than wide)", |
| 69 | + scales=list(draw=TRUE), |
| 70 | + colorkey=FALSE)) |
| 71 | + |
| 72 | +print(ggplot(test_data, aes(x=x, y=y, fill=value)) + |
| 73 | + geom_tile() + |
| 74 | + coord_fixed(ratio=2) + |
| 75 | + ggtitle("ggplot: ratio=2 (cells 2x taller than wide)") + |
| 76 | + theme_minimal() + |
| 77 | + theme(aspect.ratio=NULL)) |
| 78 | + |
| 79 | +cat("\n=== SUMMARY ===\n") |
| 80 | +cat("For aspect=1: cells should be SQUARE\n") |
| 81 | +cat("For aspect=1.5: cells should be rectangular (1.5x taller)\n") |
| 82 | +cat("For aspect=2: cells should be very tall rectangles (2x taller)\n") |
| 83 | +cat("\nDo the ggplot versions show this correctly?\n") |
| 84 | +cat("Do the lattice versions match the ggplot versions?\n") |
0 commit comments