Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 基于多因素条件标注的成对条形图_R_Ggplot2_Tidyverse_Purrr_Mutate - Fatal编程技术网

R 基于多因素条件标注的成对条形图

R 基于多因素条件标注的成对条形图,r,ggplot2,tidyverse,purrr,mutate,R,Ggplot2,Tidyverse,Purrr,Mutate,我试图为以下数据示例创建一个图形输出,如下图所示,但我包含的代码给出了一个错误: mutate_impl.data中的错误,点:计算错误:n列的长度必须是行数的43或1,而不是42 我的目标是在同一图表上绘制来自同一位置的所有提供商,然后在轴上只包含一个名称,以便每个提供商可以看到他们与所在区域的其他提供商的比较,而不显示其他提供商的身份。我尝试指定n=43是完整数据集的长度,但没有成功。此外,我想做一个成对的条形图,显示每个供应商如何比较其前几个月的费率。 我猜scale_x_discret

我试图为以下数据示例创建一个图形输出,如下图所示,但我包含的代码给出了一个错误:

mutate_impl.data中的错误,点:计算错误:n列的长度必须是行数的43或1,而不是42

我的目标是在同一图表上绘制来自同一位置的所有提供商,然后在轴上只包含一个名称,以便每个提供商可以看到他们与所在区域的其他提供商的比较,而不显示其他提供商的身份。我尝试指定n=43是完整数据集的长度,但没有成功。此外,我想做一个成对的条形图,显示每个供应商如何比较其前几个月的费率。


我猜scale_x_discrete的包装器,包含breaks=和labels=的变量,可能会有所帮助。我意识到我标记为重复的问题也是你发布的。这个问题和你之前的问题到底有什么不同?
  Provider  Month   Payment Location
    Andrew  2   32.62   OH
    Dillard 2   40  OH
    Henry   2   32.28   OH
    Lewis   2   47.79   IL
    Marcus  2   73.04   IL
    Matthews    2   45.22   NY
    Paul    2   65.73   NY
    Reed    2   27.67   NY
    Andrew  1   33.23   OH
    Dillard 1   36.63   OH
    Henry   1   42.68   OH
    Lewis   1   71.45   IL
    Marcus  1   39.51   IL
    Matthews    1   59.11   NY
    Paul    1   27.67   NY
    Reed    1   28.78   NY

library(tidyverse)
    library(purrr)
    df <- 1:nrow(PaymentsFeb) %>% 
         purrr::map( ~PaymentsFeb) %>% 
         set_names(PaymentsFeb$Provider) %>% 
         bind_rows(.id = "ID") %>% 
         nest(-ID) %>%  

     mutate(Location=map2(data,ID, ~.x %>% filter(Provider == .y) %>% select(Location))) %>% 
     mutate(data=
           map2(data, ID, ~.x %>% 
                  mutate(n=paste0("#", sample(seq_len(n()), size = n())),
                         Provider=ifelse(Provider == .y, as.character(Provider), n),
                         Provider=factor(Provider, levels = c(.y, sample(n, n())))))) %>%
     mutate(plots=map2(data,Location, ~ggplot(data=.x,aes(x = Provider, y = scores, fill = scores))+ 
               geom_col() +geom_text(aes(label=Per.Visit.Bill.Rate), vjust=-.3)+
               ggtitle("test scores by Location-  February 2018", subtitle = .y$Location)
     ))