小编Ric*_*ton的帖子

数组切片中的多个组件 - 相当于perl5:@a [0..1,3]

非常基本的问题,但我似乎无法找到有关文档中多个范围的任何内容.

如何从perl6数组中选择多个范围?

my @a = "a","b","c","d";

@a[0..1,3] # expecting array with a, b & d as p5
Run Code Online (Sandbox Code Playgroud)

这似乎回到一种嵌套列表的,什么是Perl 6的语法acheive结果,这将在Perl 5(即数组一代产量a,b&d)?

slice perl6 raku

11
推荐指数
2
解决办法
120
查看次数

在以编程方式生成的 Rmarkdown 中“打印”HTML 小部件

我正在尝试以编程方式生成一些 Rmarkdown,其中一个部分包含一个 HTML 小部件。如果它们在我的函数中位于最后,那么它们的输出就很好。但是,如果我将它们包装在 a 中,print这样我就可以在它们后面放置其他内容,就像对绘图所做的那样,它们不会产生任何输出。

也许这与处理打印的方式有关,knitr我不确定。但是有谁知道如何让 HTML 小部件表现得像以编程方式生成的 Rmarkdown 中的绘图一样?

示例.Rmd

---
title: "R Notebook"
output:
  html_document:
    df_print: paged
---

```{r}
ex_plot <- ggplot2::ggplot(iris, ggplot2::aes(Sepal.Length,Sepal.Width)) + 
    ggplot2::geom_point()

gen_rmarkdown_widget_last <- function() {
    cat("# Head 1\n\n")
    DT::datatable(iris)
}

gen_rmarkdown_plots <- function() {
    cat("# Head 1\n\n")
    print(ex_plot)
    cat("# Head 2\n\n")
}

gen_rmarkdown_widgets <- function() {
    cat("# Head 1\n\n")
    print(DT::datatable(iris))

    # tried loading from file
    # tmp <- tempfile()
    # htmlwidgets::saveWidget(DT::datatable(iris), tmp)
    # knitr::include_url(tmp)
    
    # tried a different widget …
Run Code Online (Sandbox Code Playgroud)

r knitr r-markdown htmlwidgets

7
推荐指数
1
解决办法
1072
查看次数

堆栈条形图 (ggplot) 上的乱序文本标签

我正在尝试制作带有文本标签的堆积条形图,这是一些示例数据/代码:

library(reshape2)

ConstitutiveHet <- c(7,13)
Enhancer <- c(12,6)
FacultativeHet <- c(25,39)
LowConfidence <- c(3,4)
Promoter <- c(5,4)
Quiescent <- c(69,59)
RegPermissive <- c(23,18)
Transcribed <- c(12,11)
Bivalent <- c(6,22)
group <- c("all","GWS")

meanComb <- data.frame(ConstitutiveHet,Enhancer,LowConfidence,Promoter,Quiescent,RegPermissive,Transcribed,Bivalent,group)
meanCombM <- melt(meanComb,id.vars = "group")

ggplot(meanCombM,aes(group,value,label=value)) +
     geom_col(aes(fill=variable))+
     geom_text(position = "stack")+
     coord_flip()
Run Code Online (Sandbox Code Playgroud)

文本标签出现乱序,它们似乎是其预期顺序的镜像。(无论是否使用 ,您都会遇到相同的问题coord_flip()

一个海报在这里有类似的问题: ggplot2:将有序类别标签添加到堆积条形图

对他们帖子的回答建议颠倒组中值的顺序,我尝试过(见下文),结果图上的顺序不是我能够弄清楚的。此外,这种方法似乎很笨拙,这里有错误还是我遗漏了什么?

x <- c(rev(meanCombM[meanCombM$group=="GWS",]$value),rev(meanCombM[meanCombM$group=="all",]$value))

ggplot(meanCombM,aes(group,value,label=x)) +
geom_col(aes(fill=variable))+
geom_text(position = "stack")+
coord_flip()
Run Code Online (Sandbox Code Playgroud)

r ggplot2 stacked-chart geom-text

2
推荐指数
1
解决办法
1481
查看次数

标签 统计

r ×2

geom-text ×1

ggplot2 ×1

htmlwidgets ×1

knitr ×1

perl6 ×1

r-markdown ×1

raku ×1

slice ×1

stacked-chart ×1