Skip to content

Commit c6f8bcd

Browse files
committed
tables support
1 parent 32830e9 commit c6f8bcd

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

R/plotShape.R

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,21 @@ NULL
3737
#' @importFrom utils tail
3838
#' @export
3939
setMethod("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

Comments
 (0)