|
| 1 | +From j3||d|ck @end|ng |rom gm@||@com Wed Nov 5 08:54:36 2025 |
| 2 | +From: j3||d|ck @end|ng |rom gm@||@com (Jeffrey Dick) |
| 3 | +Date: Wed, 5 Nov 2025 15:54:36 +0800 |
| 4 | +Subject: [Rd] Mismatch between iris data and symbols in matplot example |
| 5 | +Message-ID: <0a710fc9-4d45-46a9-8803-9147ed6b10a4@gmail.com> |
| 6 | + |
| 7 | +Setosa sepals are bigger than petals in both length and width: |
| 8 | + |
| 9 | +summary(subset(iris, Species == "setosa")) |
| 10 | + |
| 11 | + ? Sepal.Length? ? Sepal.Width? ? ?Petal.Length? ? Petal.Width ? Species |
| 12 | + ?Min.? ?:4.300? ?Min.? ?:2.300? ?Min.? ?:1.000? ?Min.? ?:0.100 ?setosa? ? :50 |
| 13 | + ?1st Qu.:4.800? ?1st Qu.:3.200? ?1st Qu.:1.400? ?1st Qu.:0.200 ?versicolor: 0 |
| 14 | + ?Median :5.000? ?Median :3.400? ?Median :1.500? ?Median :0.200 ?virginica : 0 |
| 15 | + ?Mean? ?:5.006? ?Mean? ?:3.428? ?Mean? ?:1.462? ?Mean? ?:0.246 |
| 16 | + ?3rd Qu.:5.200? ?3rd Qu.:3.675? ?3rd Qu.:1.575? ?3rd Qu.:0.300 |
| 17 | + ?Max.? ?:5.800? ?Max.? ?:4.400? ?Max.? ?:1.900? ?Max.? ?:0.600 |
| 18 | + |
| 19 | +However, in the first example with iris in ?matplot, setosa petals (small red "s") appear to be longer and wider than sepals (big blue "S"). The symbols for versicolor are also swapped. (I'm using R 4.5.2.) |
| 20 | + |
| 21 | +A possible fix is to change legend() to put "Sepals" before "Petals" for both species. This ordering corresponds with the column indexing used in the example: |
| 22 | + |
| 23 | +iS <- iris$Species == "setosa" |
| 24 | +names(iris[iS,c(1,3)]) == c("Sepal.Length", "Petal.Length") |
| 25 | +names(iris[iS,c(2,4)]) == c("Sepal.Width", "Petal.Width") |
| 26 | + |
| 27 | +The original legend used bigger (uppercase) symbols for bigger flower parts. Whether or not this was intentional, it is an intuitive choice. Such a congruence can be maintained by changing "sS" to "Ss" and "vV" to "Vv" in all three pch assignments. |
| 28 | + |
| 29 | +Here is a modified example with the proposed changes in legend and pch. |
| 30 | + |
| 31 | +table(iris$Species) # is data.frame with 'Species' factor |
| 32 | +iS <- iris$Species == "setosa" |
| 33 | +iV <- iris$Species == "versicolor" |
| 34 | +op <- par(bg = "bisque") |
| 35 | +matplot(c(1, 8), c(0, 4.5), type =? "n", xlab = "Length", ylab = "Width", |
| 36 | + ? ? ? ? main = "Petal and Sepal Dimensions in Iris Blossoms") |
| 37 | +matpoints(iris[iS,c(1,3)], iris[iS,c(2,4)], pch = "Ss", col = c(2,4)) |
| 38 | +matpoints(iris[iV,c(1,3)], iris[iV,c(2,4)], pch = "Vv", col = c(2,4)) |
| 39 | +legend(1, 4, c("? ? Setosa Sepals", "? ? Setosa Petals", |
| 40 | + ? ? ? ? ? ? ? ?"Versicolor Sepals", "Versicolor Petals"), |
| 41 | + ? ? ? ?pch = "SsVv", col = rep(c(2,4), 2)) |
| 42 | + |
| 43 | +Regards, |
| 44 | +Jeff Dick |
| 45 | + |
| 46 | + |
| 47 | +From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch Wed Nov 5 22:18:38 2025 |
| 48 | +From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler) |
| 49 | +Date: Wed, 5 Nov 2025 22:18:38 +0100 |
| 50 | +Subject: [Rd] Mismatch between iris data and symbols in matplot example |
| 51 | +In-Reply-To: <fake-VM-id.713c81f245471d6f8474ae183cd3ea43@talos.iv> |
| 52 | +References: <0a710fc9-4d45-46a9-8803-9147ed6b10a4@gmail.com> |
| 53 | +Message-ID: <26891.48942.664700.706474@stat.math.ethz.ch> |
| 54 | + |
| 55 | +>>>>> Jeffrey Dick on Wed, 5 Nov 2025 15:54:36 +0800 writes: |
| 56 | + |
| 57 | + > Setosa sepals are bigger than petals in both length and width: |
| 58 | + > summary(subset(iris, Species == "setosa")) |
| 59 | + |
| 60 | + > ? Sepal.Length? ? Sepal.Width? ? ?Petal.Length? ? Petal.Width ? Species |
| 61 | + > Min. :4.300 Min. :2.300 Min. :1.000 Min. :0.100 setosa :50 |
| 62 | + > 1st Qu.:4.800 1st Qu.:3.200 1st Qu.:1.400 1st Qu.:0.200 versicolor: 0 |
| 63 | + > Median :5.000 Median :3.400 Median :1.500 Median :0.200 virginica : 0 |
| 64 | + > Mean :5.006 Mean :3.428 Mean :1.462 Mean :0.246 |
| 65 | + > 3rd Qu.:5.200 3rd Qu.:3.675 3rd Qu.:1.575 3rd Qu.:0.300 |
| 66 | + > Max. :5.800 Max. :4.400 Max. :1.900 Max. :0.600 |
| 67 | + |
| 68 | + > However, in the first example with iris in ?matplot, setosa petals (small red "s") appear to be longer and wider than sepals (big blue "S"). The symbols for versicolor are also swapped. (I'm using R 4.5.2.) |
| 69 | + |
| 70 | + > A possible fix is to change legend() to put "Sepals" before "Petals" for both species. This ordering corresponds with the column indexing used in the example: |
| 71 | + |
| 72 | + > iS <- iris$Species == "setosa" |
| 73 | + > names(iris[iS,c(1,3)]) == c("Sepal.Length", "Petal.Length") |
| 74 | + > names(iris[iS,c(2,4)]) == c("Sepal.Width", "Petal.Width") |
| 75 | + |
| 76 | + > The original legend used bigger (uppercase) symbols for bigger flower parts. Whether or not this was intentional, it is an intuitive choice. Such a congruence can be maintained by changing "sS" to "Ss" and "vV" to "Vv" in all three pch assignments. |
| 77 | + |
| 78 | + > Here is a modified example with the proposed changes in legend and pch. |
| 79 | + |
| 80 | + > table(iris$Species) # is data.frame with 'Species' factor |
| 81 | + > iS <- iris$Species == "setosa" |
| 82 | + > iV <- iris$Species == "versicolor" |
| 83 | + > op <- par(bg = "bisque") |
| 84 | + > matplot(c(1, 8), c(0, 4.5), type = "n", xlab = "Length", ylab = "Width", |
| 85 | + > main = "Petal and Sepal Dimensions in Iris Blossoms") |
| 86 | + > matpoints(iris[iS,c(1,3)], iris[iS,c(2,4)], pch = "Ss", col = c(2,4)) |
| 87 | + > matpoints(iris[iV,c(1,3)], iris[iV,c(2,4)], pch = "Vv", col = c(2,4)) |
| 88 | + > legend(1, 4, c(" Setosa Sepals", " Setosa Petals", |
| 89 | + > "Versicolor Sepals", "Versicolor Petals"), |
| 90 | + > pch = "SsVv", col = rep(c(2,4), 2)) |
| 91 | + |
| 92 | + > Regards, |
| 93 | + > Jeff Dick |
| 94 | + |
| 95 | +Thanks a lot, Jeff. |
| 96 | + |
| 97 | +This is an absolute record find in "R history": |
| 98 | +This example has been *unchanged* in the matplot.Rd file already |
| 99 | + |
| 100 | +in R's svn rev 2 -- file date 18. Sep 1997 |
| 101 | + -- almost 2.5 years before R version 1.0.0 |
| 102 | + |
| 103 | +i.e., more than 28 years ago.... and you did properly find an |
| 104 | +error, indeed, even though only in the plot labeling. |
| 105 | + |
| 106 | +I will fix it slightly differently than you, keeping the legend |
| 107 | +identical, and using slightly more "principled" code.... |
| 108 | + |
| 109 | +basically this: |
| 110 | + |
| 111 | +PS <- c("Petal", "Sepal") ; clr <- c(2,4) |
| 112 | +psL <- paste(PS, "Length",sep="."); Sps <- paste0(" Setosa ", PS, "s") |
| 113 | +psW <- paste(PS, "Width", sep="."); Vps <- paste0("Versicolor ", PS, "s") |
| 114 | +matplot(c(1, 8), c(0, 4.5), type = "n", xlab = "Length", ylab = "Width", |
| 115 | + main = "Petal and Sepal Dimensions in Iris Blossoms -- new version" ) |
| 116 | +matpoints(iris[iS, psL], iris[iS, psW], pch = "sS", col = clr) |
| 117 | +matpoints(iris[iV, psL], iris[iV, psW], pch = "vV", col = clr) |
| 118 | +legend(1, 4, c(Sps, Vps), pch = "sSvV", col = rep(clr, 2)) |
| 119 | + |
| 120 | +--- |
| 121 | +Thanks again, Jeff! |
| 122 | + |
| 123 | +Martin |
| 124 | + |
| 125 | +-- |
| 126 | +Martin Maechler |
| 127 | +ETH Zurich and R Core team |
| 128 | + |
| 129 | + |
| 130 | +From iuke-tier@ey m@iii@g oii uiow@@edu Tue Nov 11 22:52:43 2025 |
| 131 | +From: iuke-tier@ey m@iii@g oii uiow@@edu (iuke-tier@ey m@iii@g oii uiow@@edu) |
| 132 | +Date: Tue, 11 Nov 2025 15:52:43 -0600 (CST) |
| 133 | +Subject: [Rd] Using STRING_PTR in a package now produces a WARNING in R-devel |
| 134 | +Message-ID: <34ee9f22-0f15-6ab9-2cdc-0418a8094632@uiowa.edu> |
| 135 | + |
| 136 | +R CMD check now produceS a WARNING if a package uses STRING_PTR. If |
| 137 | +your use of the pointer is read-only then you can call STRING_PTR_RO |
| 138 | +instead. If your code is writing to the string data then you will |
| 139 | +need to change your code. The only supported way to modify string data |
| 140 | +is to use SET_STRING_ELT. This restriction is necessary to preserve |
| 141 | +the integrity of the memory management system. |
| 142 | + |
| 143 | +Best, |
| 144 | + |
| 145 | +luke |
| 146 | + |
| 147 | +-- |
| 148 | +Luke Tierney |
| 149 | +Ralph E. Wareham Professor of Mathematical Sciences |
| 150 | +University of Iowa Phone: 319-335-3386 |
| 151 | +Department of Statistics and Fax: 319-335-3017 |
| 152 | + Actuarial Science |
| 153 | +241 Schaeffer Hall email: luke-tierney at uiowa.edu |
| 154 | +Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu |
| 155 | + |
| 156 | + |
0 commit comments