[与14382209类似的问题,但那里的建议没有解决这个问题]
\n\n在 Windows 7 工作计算机上新安装 R 4.0.0tidyverse会返回此经典的“无法创建锁定目录”错误
install.packages(\'tidyverse\')\nWARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:\n\nhttps://cran.rstudio.com/bin/windows/Rtools/\nInstalling package into \xe2\x80\x98\\\\ukbia04sfsrv002.a04.dt21.svcs.hp.com/users/A04/ocarrib/R/win-library/4.0\xe2\x80\x99\n(as \xe2\x80\x98lib\xe2\x80\x99 is unspecified)\nalso installing the dependencies \xe2\x80\x98highr\xe2\x80\x99, \xe2\x80\x98markdown\xe2\x80\x99, \xe2\x80\x98testthat\xe2\x80\x99, \xe2\x80\x98RColorBrewer\xe2\x80\x99, \xe2\x80\x98viridisLite\xe2\x80\x99, \xe2\x80\x98askpass\xe2\x80\x99, \xe2\x80\x98rematch\xe2\x80\x99, \xe2\x80\x98prettyunits\xe2\x80\x99, \xe2\x80\x98processx\xe2\x80\x99, \xe2\x80\x98knitr\xe2\x80\x99, \xe2\x80\x98yaml\xe2\x80\x99, \xe2\x80\x98htmltools\xe2\x80\x99, \xe2\x80\x98evaluate\xe2\x80\x99, \xe2\x80\x98base64enc\xe2\x80\x99, \xe2\x80\x98tinytex\xe2\x80\x99, \xe2\x80\x98xfun\xe2\x80\x99, \xe2\x80\x98backports\xe2\x80\x99, \xe2\x80\x98generics\xe2\x80\x99, \xe2\x80\x98reshape2\xe2\x80\x99, \xe2\x80\x98assertthat\xe2\x80\x99, \xe2\x80\x98glue\xe2\x80\x99, \xe2\x80\x98fansi\xe2\x80\x99, \xe2\x80\x98DBI\xe2\x80\x99, \xe2\x80\x98lifecycle\xe2\x80\x99, \xe2\x80\x98R6\xe2\x80\x99, \xe2\x80\x98tidyselect\xe2\x80\x99, \xe2\x80\x98ellipsis\xe2\x80\x99, \xe2\x80\x98pkgconfig\xe2\x80\x99, \xe2\x80\x98Rcpp\xe2\x80\x99, \xe2\x80\x98BH\xe2\x80\x99, \xe2\x80\x98plogr\xe2\x80\x99, \xe2\x80\x98digest\xe2\x80\x99, \xe2\x80\x98gtable\xe2\x80\x99, \xe2\x80\x98isoband\xe2\x80\x99, \xe2\x80\x98scales\xe2\x80\x99, …Run Code Online (Sandbox Code Playgroud) 我不明白为什么我不能改变这个 geom_bar 情节的填充美学
# Reprex dataset
df <- structure(list(modality = c("Biological therapy", "Biological therapy",
"Biological therapy", "Hormone treatment", "Chemotherapy", "Hormone treatment",
"Biological therapy", "Biological therapy", "Hormone treatment",
"Chemotherapy"), impact = c("Interrupted", "As planned", "Interrupted",
"As planned", "As planned", "As planned", "Interrupted", "Interrupted",
"As planned", "Interrupted")), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))
Run Code Online (Sandbox Code Playgroud)
这是较大数据框(~2000)的前 10 行,我想在其中自动计算和绘制组的比例modality并按组大小排序(将是更大图的侧面板)
绘图功能:
library(tidyverse)
bar <- df %>%
ggplot(aes(x = fct_rev(fct_infreq(modality)),
y = ..prop..,
group = 1), stat = 'count') +
geom_bar(aes(fill = …Run Code Online (Sandbox Code Playgroud)