Skip to content
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

折线图优化 #77

Open
yanwuanxin opened this issue Jul 1, 2024 · 3 comments
Open

折线图优化 #77

yanwuanxin opened this issue Jul 1, 2024 · 3 comments

Comments

@yanwuanxin
Copy link

建议优化:在绘制折线图时 membership 数值小的绘制在底层 数值大的绘制在上层
image

理想效果:
image

@junjunlab
Copy link
Owner

上面下面两个图都是clusterGvis画的?怎么完成的?

@yanwuanxin
Copy link
Author

上面的图是 visCluster()绘制的 下面是通过ggplot绘制的,实现步骤:步骤1、根据 membership 划分窗口;步骤2、for 循环画图;
image

  1. 窗口划分:
    ` splitBox <- seq(min(dataFinal$membership), max(dataFinal$membership), length.out=clusterNum)
    splitBox[1] <- min(dataFinal$membership)-1
    splitBox[length(splitBox)] <- Inf

splitName <- str_c("bin_", c(1:(length(splitBox)-1)))

dataFinal$bin <- as.character(cut(dataFinal$membership, splitBox, splitName))
dataFinal$bin <- factor(dataFinal$bin, levels = mixedsort(unique(dataFinal$bin)))`

image

  1. 绘图代码:
    ` p <- ggplot()
    for (i in levels(dataFinal$bin)) {
    p <- p +
    geom_line(data = dplyr::filter(dataFinal, bin == i), aes(x = timeBin,y = expLevels, color = membership, group = gene), size = 0.1)
    }
    p <- p +
    scale_color_gradient2(low = ms.col[1],mid = ms.col[2],high = ms.col[3], midpoint = 0.5) +
    theme_classic() +
    labs(x = XaxisName, y = yaxisName) +

    facet_grid(~cluster, scales = 'free', nrows = rowsCount) +

    facet_wrap(~cluster, scales = 'free', nrow = rowsCount) +
    theme(strip.background = element_rect(fill = "transparent", color = "transparent"),
    strip.text.x = element_text(size = 13, color = "black")) +
    theme(axis.text.x = element_blank(),
    axis.title.x = element_text(color = "black", size = 17),
    axis.ticks.x = element_blank(),
    axis.text.y = element_text(color = "black", size = 13),
    axis.title.y = element_text(color = "black", size = 17),
    legend.text = element_text(color = "black", size = 13)) +
    theme(legend.position="none")`

另外,这个折线图的图例意义不大,个人觉得可以不展示图例

@junjunlab
Copy link
Owner

已经优化,感谢建议,图例的话可以自己用ggplot语法进行隐藏或者去除。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants