小编jer*_*erH的帖子

有没有一种巧妙的方法可以在 R GT 表中获取两个列扳手标签?

下面的代码

library(magrittr)
library(gt)
library(dplyr)

TestColumn_one <- c("CA", "FL", "GA", "MA", "NM", "OH", "OK", "TN", "UT")
TestColumn_two <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
TestColumn_three <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
TestColumn_four <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
TestColumn_five <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
TestColumn_six <- c("Community 1",
                    "Community 2",
                    "Community 3",
                    "Community 4",
                    "Community 5",
                    "Community 6",
                    "Community 7",
                    "Community 8",
                    "Community 9")
TestColumn_seven …
Run Code Online (Sandbox Code Playgroud)

r gt

6
推荐指数
2
解决办法
2930
查看次数

gganimate 图中的标签行为问题

我有以下生成静态图表的 R 脚本

library(ggplot2)  
library(dplyr)    
library(tidyr)    
library(stringr)  
library(gtable)
library(cowplot)
library(ggrepel)
library(tidyquant)
library(gganimate)
library(gifski)

################################## BASIC SETUP TASKS ###############################
plotDate="May19"
basepath = "C:/Users/your output path here/"    


#Countries with testing data reported
#going to leave out Spain because their data is so sporadic
testCountries <- c("ARG", "AUS", "AUT","BEL","BGD","BHR","BGR","BOL","CAN","CHE",
                   "CHL","COL","CRI","CUB","CZE","DEU","DNK","ECU","EST",
                   "ETH","FIN","FRA","GBR","GHA","GRC","HKG","HRV","HUN","IDN",
                   "IND","IRL","IRN","ISL","ISR","ITA","JPN","KAZ","KEN","KOR",
                   "LTU","LUX","LVA","MAR","MEX","MMR","MYS","NGA","NLD","NOR",
                   "NPL","NZL","PAK","PAN","PER","PHL","POL","PRT","PRY","ROU",
                   "RUS","RWA","SEN","SGP","SLV","SRB","SVK","SVN","SWE","THA",
                   "TUN","TUR","TWN","UGA","URY","USA","VNM","ZAF")

# Get population data
url <- "https://population.un.org/wpp/Download/Files/1_Indicators%20(Standard)/CSV_FILES/WPP2019_TotalPopulationBySex.csv"

pops <- read.csv(url, stringsAsFactors = FALSE, header = TRUE)
pops <- pops %>% filter(Time==2020) %>% select(Location, PopTotal) %>% distinct()
pops$PopTotal …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 gganimate

4
推荐指数
1
解决办法
305
查看次数

通过代码保存echarts4r图像(再次)

我早些时候在这里问过这个问题,但它被标记为重复并关闭。不幸的是,我指出的答案不起作用......

所以,再次:

我可以制作一个 eCharts4r 仪表,例如

library(echarts4r) 
library(magrittr)

CA_gauge <- e_charts() %>% 
  e_gauge(4.1, 
          "INCIDENCE", 
          min=0, 
          max=20,
          axisLine = list(
            linestyle = list(
              color=list(
                c(1.5/20, "green"),
                c(3/20, "yellow"),
                c(1, "red")
              )
            ))) %>% 
  e_title("CA")

print(CA_gauge)
Run Code Online (Sandbox Code Playgroud)

但我还没有找到将输出保存到文件以便稍后在表中使用它的好方法gt。我能找到的最好的方法是将“saveAsImage”添加到输出中

e_charts() %>% 
      e_gauge(4.1, 
              "INCIDENCE", 
              min=0, 
              max=20,
              axisLine = list(
                linestyle = list(
                  color=list(
                    c(1.5/20, "green"),
                    c(3/20, "yellow"),
                    c(1, "red")
                  )
                ))) %>% 
        e_toolbox_feature(feature = c("saveAsImage"))
Run Code Online (Sandbox Code Playgroud)

这会在 RStudio 查看器的右上角添加一个“另存为”按钮

在此输入图像描述

但我真正想做的只是将代码中的图像(显然没有动画)保存到 tiff/jpg/png 图像文件中。我每周为一个工作项目制作大约十几个这样的文件,所以我一直手动保存这些文件。但它们很受欢迎,老板想要一个包含 75 个以上的新版本。

我尝试使用标准设备,例如

tiff(paste("CA_gauge.tif",sep=""), 
     res=600, compression = "lzw", height=5, width=15, units="in") …
Run Code Online (Sandbox Code Playgroud)

r echarts4r

3
推荐指数
1
解决办法
1184
查看次数

如何在 R 中的两个数据帧之间查找和替换值

我有一个来自 tidytext 的数据框,其中包含一些调查自由回复评论中的单个单词。它只有不到 500,000 行。作为自由反应数据,它充满了错别字。使用 textclean::replace_misspellings 处理了近 13,000 个拼写错误的单词,但仍有大约 700 个我手动识别的独特拼写错误。

我现在有一个包含两列的第二个表,第一个是拼写错误,第二个是更正。

例如

allComments <- data.frame("Number" = 1:5, "Word" = c("organization","orginization", "oragnization", "help", "hlp"))
misspellings <- data.frame("Wrong" = c("orginization", "oragnization", "hlp"), "Right" = c("organization", "organization", "help"))
Run Code Online (Sandbox Code Playgroud)

我怎么能代替所有的值allComments$word相匹配的misspellings$wrongmisspellings$right

我觉得这可能是非常基本的,而且我的 R 无知正在显示......

text r

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

带有 geom_label_repel 的文本颜色

不特定于任何特定的代码段,是否有一种相对简单的方法来更改 geom_label_repel 框中的文本颜色?

具体来说,我有生成以下图表的代码

在此处输入图片说明

标签框中的百分比是最近一周的 7 天移动平均线与前一周相比的百分比变化。我只想在值为正时将文本着色为红色,在值为负时将其着色为绿色。

此图表的数据框可以从这里复制。

情节代码是

#endpoint layer
BaseEndpoints <- smDailyBaseData %>% filter(Base %in% AFMCbases) %>%
  group_by(Base) %>%
  filter(DaysSince == max(DaysSince)) %>%
  select(Base, abbv, DaysSince, newRate,label) %>%
  ungroup()

ZoomEndpoints <- BaseEndpoints %>% filter(Base != 'Edwards') %>%
  mutate(zoom = TRUE)
CAEndPoint <- BaseEndpoints %>% filter(Base == 'Edwards') %>%
  mutate(zoom = FALSE)

ZoomEndpoints <- rbind(ZoomEndpoints, CAEndPoint)

BasePlot <- smDailyBaseData %>% filter(Base %in% AFMCbases) %>%
  ggplot(mapping = aes(x = as.numeric(DaysSince), y = newRate)) +
  geom_line(aes(color=abbv),show.legend = FALSE) + …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 ggrepel

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

标签 统计

r ×5

ggplot2 ×2

echarts4r ×1

gganimate ×1

ggrepel ×1

gt ×1

text ×1