# Loading data
data(CPS85, package = "mosaicData")
# Count the number of females and males in each sector
plotdata <- group_by(CPS85,sector) %>%
count(sex)
# Print the data
print(plotdata)
# Construct a ggplot object according requirement above and assign it to 'plt'
plt <- ggplot(plotdata,
aes(x = sector,
y = n))+
geom_col(aes(fill=sex))+
geom_text(aes(label=n),
position = position_stack(vjust = 0.5))+
labs(x = "",
y = "Number of persons",
title = "")
# Display the stacked bar chart
plt
Run Code Online (Sandbox Code Playgroud)
我怎样才能改变我的 vjust 使数字位于堆积条的中间
如果有人能帮助我用 R 制作单个堆叠条形图,我将不胜感激。这是要绘制的数据的一个小示例:
cell_type Percentage
CD20 B cells 15.00
CD4 T cells 25.00
Other cells 60.00
Run Code Online (Sandbox Code Playgroud)
这是我用过的,但不能修改太多。
p1 <- ggplot(Data, aes(x = "", y = percentage, fill = cell_type))
p1
p2 <- p1 + geom_col()
p2
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助。
我想在 HTML 中多次使用同一个脚注Quarto。问题是,一旦我创建脚注并使用它两次,它将显示为两个脚注。这是一个可重现的示例:
---
title: "Footnote multiple times"
editor: visual
format: html
---
Some example text for a footnote[^1].
Some example text for same footnote[^1].
[^1]: Example footnote.
Run Code Online (Sandbox Code Playgroud)
输出:
正如您所看到的,脚注显示为两个单独的脚注(重复),而我创建了一个脚注。所以我想知道是否有人知道如何创建一个脚注并在 HTML 四开本中多次使用它?
我确信这是一个非常简单的修复,但我似乎找不到答案...我试图在数据框的末尾创建一个列,它是特定值的次数总和(例如“1”)出现在该行上。例如,如果我从以下数据框开始:
X1 <- c(5,1,7,8,1,5)
X2 <- c(5,0,0,2,3,7)
X3 <- c(6,2,3,4,1,7)
X4 <- c(1,1,5,2,1,7)
df <- data.frame(id,X1,X2,X3,X4)
id X1 X2 X3 X4
1 1 5 5 6 1
2 2 1 0 1 1
3 3 7 0 3 5
4 4 8 2 4 2
5 5 1 3 2 1
6 6 5 7 7 7
Run Code Online (Sandbox Code Playgroud)
我试图确定值“1”在该行中出现了多少次,我希望输出如下所示:
id X1 X2 X3 X4 one_appears
1 1 5 5 6 1 2
2 2 1 0 1 1 3
3 3 …Run Code Online (Sandbox Code Playgroud) 当我点击这张幻灯片时,我想zoom在图表上显示。我应该像动画一样。这是一些可重现的代码:
---
title: "Zoom on graph in slide"
format: revealjs
---
## Start
- I would like to zoom to the graph clicking on this slide
```{r}
#| echo: false
library(ggplot2)
ggplot(mtcars, aes(x = cyl, y = mpg)) +
geom_point()
```
Run Code Online (Sandbox Code Playgroud)
输出:
我希望图表变成动画,以便它缩放到图表。我zoom在上面的链接中找到了该选项,但我不确定如何将其用作动画。所以我想知道是否有人知道如何在revealjs Quarto中制作缩放动画?
我想知道是否可以运行代码块的一部分而不注释我们不想运行的行。例如我们有以下 qmd 文件:
---
title: "Run only part of code chunk without commenting"
---
```{r}
data(trees)
head(trees)
plot(Girth ~ Height, data = trees, pch=16)
mod <- lm(Girth ~ Height, data = trees)
summary(mod)
```
Run Code Online (Sandbox Code Playgroud)
假设我们只想运行第 6 行到第 9 行,我们该怎么做呢?我不想使用这样的评论:
---
title: "Run only part of code chunk without commenting"
---
```{r}
data(trees)
head(trees)
plot(Girth ~ Height, data = trees, pch=16)
#mod <- lm(Girth ~ Height, data = trees)
#summary(mod)
```
Run Code Online (Sandbox Code Playgroud)
这样做的主要原因是我想显示完整的代码但不想运行所有代码。当我们对某些行进行评论时,看起来不太好。所以我想知道是否有人知道这是否可能Quarto?
要么我太笨,要么我找不到正确的命令。
如何使用 ZSH 终端创建简单的 YAML 文件?
如何使用reveal.js 在我的四开本演示文稿标题幻灯片的左上角添加小徽标?
有关 Quarto/reveal.js 演示文稿的信息:https://quarto.org/docs/presentations/
我想创建一个带有超链接的按钮Streamlit。我想也许可以使用st.button这种语法:[Click Here](https://stackoverflow.com)。但不幸的是这没有成功,它只显示文本,并没有将其作为超链接。我找到了这个解决方法,但这不再有效。我不想使用st.markdown超链接,因为这不会创建按钮。这是一个可重现的示例:
"""
# Streamlit app
"""
import streamlit as st
import pandas as pd
# Button with hyperlink
st.button('[Click Here](https://stackoverflow.com)')
Run Code Online (Sandbox Code Playgroud)
输出:
如您所见,它不会创建超链接。所以我想知道是否有人知道如何在 Streamlit 中创建带有超链接的按钮?
例如,我希望在 pdf 或 csv 文档的句子中间有一个下载按钮。这意味着句子中应该有一个小按钮,建议您可以下载文档,而不是在导航或侧栏中。这是一些可重现的代码:
---
title: "Download button in text Quarto"
format:
html:
code-fold: true
engine: knitr
---
I would like to have a download button [here]() for pdf or CSV document for example.
Run Code Online (Sandbox Code Playgroud)
我不确定是否可以使用downloadthis包在句子中实现一个干净的按钮,因为它应该位于带有文本的句子的中间。