我很难从数据框中删除观察结果,然后它们会在图表上显示为轴标签。
当我使用像这个片段的代码时
#***** D A T A M A N I P U L A T I O N B R E ****
#* *
#* *
#* Deals with relevant substrates only *
#* for the mortars BMG and PA only *
#* This is in connection with BRE certificated product *
#* and change of polymer 14SSP0016 *
#* *
#* *
#*********************************************************
#
#
### Firstly Create a new variable with the substrates of interest renamed to a common system
blk <- c("block", "Breeze Block", "breezeblk", "conc.blk")
brk <- c("LBC Common", "lbccommon", "brk.common")
cnc <- c("ConcreteDense", "Coping Slab", "denseconc", "conc.dense")
eng <- c("engbrick", "brk.eng")
mydata$sub.genl <- mydata$substrate
mydata$sub.genl <- mapvalues( mydata$substrate,
from=c( blk[1],blk[2],blk[3],blk[4], brk[1],brk[2],brk[3], cnc[1],cnc[2],cnc[3],cnc[4], eng[1], eng[2], "tile" ),
to=c( blk[4],blk[4],blk[4],blk[4], brk[3],brk[3],brk[3], cnc[4],cnc[4],cnc[4],cnc[4], eng[2], eng[2], "tile" ) )
# head(mydata)
## Works OK, length(mydata$id) = 622
##
### Secondly Keep those cases on the keep.list, Drop all others
keep.list <- c(blk[4], brk[3], cnc[4], eng[2], "tile")
mydata.bre1 <- subset(mydata, sub.genl %in% keep.list )
droplevels(mydata.bre1)$sub.genl
# as.factor(as.character(mydata.bre1$sub.genl))
# mydata.bre1$product <- mydata.bre1$sub.genl[ , drop=TRUE]
# levels(mydata.bre1$sub.genl)
## Gives about 445 cases
##
### Thirdly select the products BMG and PA then Drop others
mydata.bre2 <- subset(mydata.bre1, product %in% c("PA", "BMG"))
droplevels(mydata.bre2)$product
# as.factor(as.character(mydata.bre2$product))
# mydata.bre2$product <- mydata.bre2$product[ , drop=TRUE]
# levels(mydata.bre2$product)
## Works OK length(mydata.bre2$id) = 189
##
### Fourthly drop unwanted variables e.g. $mortar
drop.list <- c(4,9,11,13:15)
mydata.bre2 <- subset(mydata, select = -drop.list )
names(mydata.bre2)
## Works OK
##
#
#
###### E N D *********************************
然后
levels(mydata.bre2$product)
结果是
[1] "" "3937939379"
[3] "610 + K622" "BMG"
[5] "CAPATECT ROLLKLEBER 615" "DMG"
[7] "DOC" "HP BASECOAT"
[9] "LA" "PA"
[11] "pBMG" "pTC (10mm) "
[13] "pTC (6mm) " "Swimming Pool Mortar + mesh"
[15] "SWIMMING POOL MORTAR 2" "SWIMMING POOL MORTAR 3"
[17] "UF BASECOAT"
当只有c(&#34; PA&#34;,&#34; BMG&#34;)应该存在时。
同上 levels(mydata.bre1$sub.genl)
[1] "" "conc.blk"
[3] "BMG" "brk.common"
[5] "brk.eng" "conc.dense"
[7] "CPB" "eps"
[9] "EPS" "LA"
[11] "mf" "MF"
[13] "OrangePS" "OSB"
[15] "PCR Y Wall Board grainy side" "PCR Y Wall Board mottled side"
[17] "phenolic" "Phenolic"
[19] "ply" "pvcsheet"
[21] "RockPanelLabelledSide" "RockPanelUnLabelledSide"
[23] "tile" "XPS"
仅限
keep.list
[1] "conc.blk" "brk.common" "conc.dense" "brk.eng" "tile"
should be present
然后当我尝试绘制
时#
boxplot(bondMPa~product, data=mydata.bre2, main="Bond strength versus product",
xlab="", ylab="Bond strength (MPa)")
X11()
boxplot(bondMPa~product+sub.genl, data=mydata.bre2, main="Bond strength versus product and substrate for BRE",
xlab="", ylab="Bond strength (MPa)", cex.axis=0.4, las=2) # This is a useful chart
结果是混乱,因为R试图用所有$产品绘制所有$ sub.genl的笛卡尔积,而不管哪种情况被丢弃。
在我看来,这一切都取决于跌落。也许我需要的不仅仅是放弃,也许我需要根除或类似。
可以就此提出建议吗?