-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reproduce a funkyheatmap using aplot #6
Comments
Dear Professor Guang, I appreciate the opportunity to contribute to the discussion. After carefully considering the problem and learning the two R package (here is my simple notes for aplot and funkheatmap). I have come up with a possible solution to try to produce that demonstrated figure of funkheatmap. The figure below is the result and following is my R codes
|
Sorry for the wrong title for you |
|
Now incorporated in the Another request is to extend This is important to work with existing code and take the advantage of For example, we can access each of the subplots and modify it using
|
@lishensuo for the pie chart, you can explore the possibility of using the |
Professor Yu, I have made an attempt based on your suggestion. I think the main problem is that funky_plot is for discrete samples with their attributes. And the scatter pie plot based on ggforce is for continuous variables (funckyheatmap package did a very complex process). Therefore, I tried to make a pseudo-axis for samples to implement it. The following is the output and its codes which could be seen as the extension of grouping funky_bar(). library(tidyverse)
library(scatterpie)
library(aplot)
library(ggfun)
library(tidyverse)
data("mtcars")
d <- yulab.utils::scale_range(mtcars[1:10,]) |>
rownames_to_column("id") |>
arrange(desc(mpg))
set.seed(1)
d$level_A = sample(1:10, nrow(d), replace = T)
set.seed(2)
d$level_B = sample(1:10, nrow(d), replace = T)
set.seed(3)
d$level_C = sample(1:10, nrow(d), replace = T)
g0 = funky_text(d, 1) + theme_blinds()
g1 = funky_bar2(d, 2) + theme_blinds()
g2 = funky_bar2(d, 13:15) + theme_blinds()
g3 = funky_bar2(d, 13:15, pie = T) + theme_blinds()
# aplot::funky_heatmap(g0, g1, g2)
aplot::funky_heatmap(g0, g1, g3)
funky_bar2 <- function(data, cols, pie=FALSE) {
d2 <- aplot:::funky_data(data, cols)
if (length(cols) == 1) {
label = names(data)[cols]
mapping <- aes(fill = .data$value)
position <- 'stack'
} else {
label = "name"
mapping <- aes(fill = .data$name)
name.levels <- names(data)[cols]
d2 <- d2 |> dplyr::mutate(name = factor(.data$name, levels = name.levels))
position <- 'fill'
}
if(pie == FALSE){
p <- ggplot(d2, aes(.data$value, .data$id)) +
#geom_col(aes(fill=.data$value), color='black', linewidth=0.3) +
geom_col(mapping=mapping, position=position, color='black', linewidth=0.3) +
aplot:::funky_theme() +
#geom_vline(xintercept = 0, linetype="dashed", linewidth=0.8) +
geom_vline(xintercept = 1, linetype="dashed", linewidth=0.8)
#scale_fill_gradient(low = "#CC4C02", high = "#FFFFE5") +
} else {
d2$pie_x = 0.5
d2$pie_y = rep(rev(seq(nrow(data))),each=length(cols))
d2$pie_r = 0.5
p = ggplot() +
geom_scatterpie(aes(x=pie_x, y=pie_y,r=pie_r),
data=d2, cols="name",
long_format=TRUE) +
coord_fixed() +
aplot:::funky_theme() +
scale_y_continuous(breaks = rev(unique(d2$pie_y)),
labels = rev(as.character(unique(d2$id))),
expand=c(0.01,0))
}
if (label == "") {
p <- p + scale_x_continuous(expand=c(0,0))
} else {
p <- p + scale_x_continuous(breaks = 0.5, labels=label, expand=c(0,0))
}
# p <- p + funky_fill_label(data, cols)
return(p)
} I think there are also some limitaions (e.g. circles must be close to each other) and haven't come up with a better way yet. |
@xiangpin pls review and incorporate it to |
using
ggplot2
to plot columns and usingaplot
to create a composite plot.Please reproduce the
funkheatmap
demonstrated in the README.The text was updated successfully, but these errors were encountered: