3737# ' @importFrom utils tail
3838# ' @export
3939setMethod ("plotShape ", "SpatialData", \(x, i=1, c=NULL, f="white", s="radius", a=0.2, assay=1) {
40+ if (is.numeric(i )) i <- shapeNames(x )[i ]
4041 df <- data(shape(x , i ))
4142 df <- st_as_sf(df )
4243 xy <- st_coordinates(df )
4344 typ <- st_geometry_type(df )
4445 typ <- as.character(typ [1 ])
4546 aes <- aes(.data [[" x" ]], .data [[" y" ]])
4647 dot <- list (fill = f , alpha = a )
47- # TODO: tables support
4848 # TODO: need separate plotting for different types of shapes
4949 switch (typ ,
5050 # POINT means circle
5151 POINT = {
5252 names(xs ) <- xs <- setdiff(names(df ), " geometry" )
5353 df <- data.frame (xy , lapply(xs , \(. ) df [[. ]]))
5454 names(df ) <- c(" x" , " y" , xs )
55- if (.str_is_col(c )) {
56- dot $ col <- c
57- } else if (is.character(c )) {
58- if (! c %in% names(df )) stop(" invalid 'c'" )
59- aes $ colour <- aes(.data [[c ]])[[1 ]]
60- }
6155 if (is.numeric(s )) {
6256 geo <- geom_point
6357 dot $ size <- s
@@ -67,6 +61,18 @@ setMethod("plotShape", "SpatialData", \(x, i=1, c=NULL, f="white", s="radius", a
6761 aes $ y0 <- df $ y
6862 aes $ r <- aes(.data [[s ]])[[1 ]]
6963 } else stop(" invalid 's'" )
64+ if (.str_is_col(c )) {
65+ dot $ col <- c
66+ } else if (is.character(c )) {
67+ if (c %in% names(df )) {
68+ aes $ colour <- aes(.data [[c ]])[[1 ]]
69+ } else {
70+ df [[c ]] <- valTable(x , i , c , assay = assay )
71+ if (scale_type(df [[c ]]) == " discrete" )
72+ df [[c ]] <- factor (df [[c ]])
73+ aes $ colour <- aes(.data [[c ]])[[1 ]]
74+ }
75+ } else stop(" invalid 'c'" )
7076 },{
7177 geo <- geom_polygon
7278 df <- data.frame (xy )
0 commit comments