我试图按照下面的方法用 R 创建一个条形图竞赛。当我尝试将它们另存为 gif 文件时,所有 png 都会被创建,然后我得到:
Error: The animation object does not specify a save_animation method
Run Code Online (Sandbox Code Playgroud)
是否因为我创建了多个文件而发生这种情况?
#This script contains a function to produce a "bar chart race" in R
#The following links were invaluable:
#https://www.blakeshaffer.ca/post/making-animated-charts-with-gganimate/
#/sf/ask/3683660571/
#load required packages:
library(tidyverse)
library(gganimate)
#inputs:
#data - the dataset, must contain a column called "year"
#x - the column which contains the numeric value to plot
#y - the column which contains the labels of the plot
#optional:
#title - title …Run Code Online (Sandbox Code Playgroud) 我有一个列表,里面有嵌套列表.
LIST2 <- list(list("USA","WY","TX","AZ","Canada", "CA", "NY", 'Russia', 'NY'),
list(c("USA","Canada","CA","WY", 'China', 'AZ', 'AZ', 'AZ', 'WY')),
list(c("USA","Australia","CA","AR", 'AZ', 'WY', 'New Zealand', 'Japan', 'Japan', 'NJ')),
list(list('Australia', 'Australia', 'Japan', 'Malaysia' )),
list(c('USA', 'Australia', 'Japan', 'Malaysia' )))
Run Code Online (Sandbox Code Playgroud)
我想以某种方式弄平第1和第4个列表,因此它们与其余部分的形式相同.这可能吗?
你好,我在这里有一个有趣的问题。假设我有一个长字符,其中包含其他城市名称。
test<-"Ucsd Medical Center, San Diego, California, USA|Yale Cancer Center, New Haven, Connecticut, USA|Massachusetts General Hospital., Boston, Massachusetts, USA|Dana Farber Cancer Institute, Boston, Massachusetts, USA|Washington University, Saint Louis, Missouri, USA|Mount SInai Medical Center, New York, New York, USA|Memorial Sloan Kettering Cancer Center, New York, New York, USA|Carolinas Healthcare System, Charlotte, North Carolina, USA|University Hospitals Case Medical Center; Seidman Cancer Center, Cleveland, Ohio, USA|Vanderbilt University Medical Center, Nashville, Tennessee, USA|Seattle Cancer Care Alliance, Seattle, Washington, USA|National Cancer Center, Gyeonggi-do, Korea, Republic …Run Code Online (Sandbox Code Playgroud) 我有下面的数据框,我想添加一个新列,其中包含该数据框每个值的百分比。就像是:
name <- c("asdad","dssdd")
number <- c(5,5)
df <- data.frame(name,number)
for (i in 1:nrow(df)) {
percentage<-df[i,1]/sum(df$number)
}
new <- cbind(df, percentage)
Run Code Online (Sandbox Code Playgroud)
但我得到的是 NA 而不是百分比。
我使用此处的确切代码来运行shinydashboardPlus。但是当我尝试运行该应用程序时,我得到:could not find function "dashboardPagePlus"。我尝试了 CRAN 和 github 版本
# for the CRAN version
install.packages("shinydashboardPlus")
# for the latest version
devtools::install_github("RinteRface/shinydashboardPlus")
Run Code Online (Sandbox Code Playgroud)
我的会话信息是:
R version 4.0.4 (2021-02-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shinydashboardPlus_2.0.0 shinydashboard_0.7.1 shiny_1.6.0
loaded via a namespace (and not attached): …Run Code Online (Sandbox Code Playgroud) 我正在尝试对每个数据进行分组year和求和,但是当创建新数据框时,列名称以恼人的“X”开头,例如“ ”而不是。当然,我可以在创建后将其删除或替换为“”,但我希望不要从一开始就创建它,因为此方法将应用于具有更多列的数据帧。 weightyearX20002000
library(tidyverse)
year<-c("2000","2000","2001","2002","2000","2002")
weight<-c(0.5,0.7,0.8,0.7,0.6,0.9)
YG<-data.frame(year,weight)
w<-data.frame(YG %>%
group_by(year) %>%
summarise(n = round(sum(weight)),
g = n()) %>%
select(-g) %>%
spread(year, n, fill = 0))
Run Code Online (Sandbox Code Playgroud) 我有下面的向量
\nc("SSD", "PCIe SSD", "PCIe SSD", "PCIe SSD", "SSD", "SSD", "SSD", \n"SSD", "SSD", "SSD", "SSD", "SSD", "TB SSD", "SSD", "SSD", "SSD", \n"SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", \n"SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", \n"SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", \n"SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", \n"SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", \n"SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "SSD", "PCIe SSD", \n"SSD", "SSD", "SSD", "SSD", …Run Code Online (Sandbox Code Playgroud) 我有下面的数据框:
Val1<-c(0.5,0.7,0.8,0.9)
Val2<-c(0.5,0.7,0.8,0.9)
Val3<-c(0.5,0.7,0.8,0.9)
Val4<-c(0.5,0.7,0.8,0.9)
vales<-data.frame(Val1,Val2,Val3,Val4)
row.names(vales)<-c("asd","dasd","dfsdf","fdff")
Run Code Online (Sandbox Code Playgroud)
我对其进行了正确处理,以便使用以下命令创建聚类散点图:
library(tidyverse) # data manipulation
library(cluster) # clustering algorithms
library(factoextra) # clustering algorithms & visualization
library(plotly)
cl<-scale(vales)
dist <- get_dist(cl)
k2 <- kmeans(cl, centers = 2, nstart = 25)
cl %>%
as_tibble() %>%
mutate(cluster = k2$cluster,
state = row.names(vales))
p2<-fviz_cluster(k2, data = cl)
p2+geom_text(aes(label=""))
#or
ggplotly(p2+geom_text(aes(label="")))
Run Code Online (Sandbox Code Playgroud)
我想删除点的标签,但我不明白为什么它们出现,而在下面的情况下却没有出现。
df <- USArrests
df <- na.omit(df)
df <- scale(df)
distance <- get_dist(df)
k2 <- kmeans(df, centers = 2, nstart = 25)
df %>%
as_tibble() %>%
mutate(cluster …Run Code Online (Sandbox Code Playgroud) 我有data.frame以下内容:
dp <- structure(list(`Demand Per Section` = c(125, 350, 100, 538, 75,
25, 138, 138, 75, 150, 37, 225, 35, 40, 125, 25, 25, 125, 50,
250, 88, 325, 4, 50, 6, 5, 500, 500, 3, 146, 5, 34, 15, 51, 2,
32, 48, 18, 5, 6, 44, 16, 46, 12, 100, 750, 15, 500, 30, 333),
`Element Name` = c("Nitric acid (concentrated)", "Sulphuric acid(concentrated)",
"2-hydroxybenzoic acid", "Acetic anhydride", "2-Naphthol",
"Sodium Hydroxide", "Phenyl hydrazine hydrochloride", "Glucose",
"Sodium acetate", …Run Code Online (Sandbox Code Playgroud) 我有下面的数据框,我用它创建了一个数据框。如何在每 3 位数字之间添加逗号?
Descs<-structure(list(Mean = c(NaN, 943330388, NaN, NaN, NaN, 543234645,
45831420, NaN, 27301292, 160818771), Median = c(NaN, 943330388,
NaN, NaN, NaN, 543234645, 45831420, NaN, 27301292, 160818771),
SD = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), MAD = c(NA,
0, NA, NA, NA, 0, 0, NA, 0, 0), MIN = c(NA, 943330388, NA,
NA, NA, 543234645, 45831420, NA, 27301292, 160818771), MAX = c(NA,
943330388, NA, NA, NA, 543234645, 45831420, NA, 27301292,
160818771), VAR = c(NA_real_, NA_real_, NA_real_, …Run Code Online (Sandbox Code Playgroud)