Removed 330 rows containing non-finite values (stat_boxplot).

I am trying to use geom_boxplot with aestetics weight but it throws an error
'Removed 330 rows containing non-finite values (stat_boxplot).'

ggplot(pos_plot,aes(x=factor(EPG,levels=c("EPP","S&D","ECR","ALDE","GUE/NGL","Greens/EFA","EFFD","ENF")),y=value,color=EPG,weight=EP))+

  • geom_jitter(position=position_jitter(width=0.2,height=0),alpha=0.8)+
  • geom_boxplot(alpha=0,show.legend=FALSE,lwd=1)+
  • scale_color_manual(limits=c("EPP","S&D","ECR","ALDE","GUE/NGL","Greens/EFA","EFDD","ENF"),
  •                  values=c("#fcdd22","#fc1414","#106da8","#ec008c","#c6262c","#44911d","#00abbc","black"))+
    
  • guides(color=guide_legend(""))+
  • theme(legend.position="bottom",
  •     axis.text.y=element_blank(),
    
  •     axis.ticks=element_blank())+
    
  • labs(x="",y="",title="Figure 1",subtitle="Left-right")+
  • facet_grid(variable~.)+
  • coord_flip()

Any advice how to solve it?

https://rstudio.cloud/project/1090011?fbclid=IwAR3-GVwjBu92AMATGmZ65pqsSGDHF6xFJ2syXWUJHRe5eHQso5gWWHkxJV8

It's really hard to tell what's going on here without data. I looked at your cloud project, and it looks like variables you reference in aes() aren't in pos_plot, but I'm guessing that you've done some manipulation beforehand…

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.packages("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

There's also a nice FAQ on how to do a minimal reprex for beginners, below:

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.

library(ggplot2)
df <- data.frame(
  stringsAsFactors = FALSE,
  EPG = c("S&D","S&D","Greens/EFA","Greens/EFA",
          "ALDE","ALDE","EPP","EPP","ECR",
          "ENF","S&D","ALDE","EPP","GREENS/EFA",
          "ALDE","ECR","GUE/NGL","EPP","ALDE",
          "Greens/EFA","GUE/NGL","EPP","ECR",
          "Greens/EFA","GUE/NGL","S&D","EPP",
          "GUE/NGL","ECR","S&D","S&D","EPP",
          "Greens/EFA","ALDE","Greens/EFA",
          "Greens/EFA","GUE/NGL","ALDE","GUE/NGL","S&D",
          "Greens/EFA","EPP","ENF","ALDE",
          "GUE/NGL","ECR","EPP","GUE/NGL","ENF",
          "EPP"),
  EP = c("3","1","1","1","3","3","2","2",
         "4","1","3","2","1","1","1","4",
         "1","29","3","11","7","5","7","1",
         "1","2","5","6","1","2","14","16",
         "4","1","1","1","5","2","1","13",
         "6","20","23","7","1","1","4","3",
         "6","1"),
  variable = c("Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right","Left-Right",
               "Left-Right","Left-Right","Left-Right",
               "Left-Right"),
  value = c(3.14411754432958,3.51470587281574,
            2.77352940113754,2.77352940113754,
            7.22058823120675,7.22058823120675,
            4.81176479089965,5.7382353804974,7.96176488817907,
            9.25882334302768,4.81176479089965,
            6.01617627943555,7.22058823120675,
            3.42205890650303,7.22058823120675,7.12794126489403,
            2.58823528321799,6.22285083709243,
            6.7929865702838,4.08484160600712,
            1.8755656630523,7.43438910799175,9.00226214265039,
            3.74632352021518,5.05882336773356,
            5.16176462670848,7.42647065650952,
            2.58823528321799,8.86764698509948,
            5.26470579303633,4.25588234449394,7.49852959338019,
            2.58823528321799,6.57205900378244,
            4.13235296342993,2.69117654219291,
            2.27941169158737,5.8823526983564,2.35661763581856,
            4.28676466659818,3.59191172439987,
            7.83823513652682,9.66310194068103,
            6.20989312677925,2.31029410633867,
            6.17830881790928,6.87316176010759,2.70404410691771,
            8.94117604550173,5.63235276269464),
  party_name = as.factor(c("PS",
                           "SPA","ECOLO","Groen","MR",
                           "VLD","cdH","CD&V","N-VA","VB",
                           "SD","RV","KF","SF","V",
                           "DF","FolkB","CDU","FDP",
                           "Grunen","Linke","CSU","AfD",
                           "Piraten","DieTier","PASOK",
                           "ND","SYRIZA","ANEL","Potami",
                           "PSOE","PP","IU","EAJ/PNV",
                           "ERC","ICV","Podemos",
                           "C's","PCF","PS","EELV","UMP",
                           "FN","MODEM","PG","FF","FG",
                           "SF","LN","UDC"))
)
ggplot(df,aes(x=factor(EPG,levels=c("EPP","S&D","ECR","ALDE","GUE/NGL","Greens/EFA","EFFD","ENF")),y=value,color=EPG,weight=EP))+
  geom_jitter(position=position_jitter(width=0.2,height=0),alpha=0.8)+
  geom_boxplot(alpha=0,show.legend=FALSE,lwd=1)+
  scale_color_manual(limits=c("EPP","S&D","ECR","ALDE","GUE/NGL","Greens/EFA","EFDD","ENF"),
                     values=c("#fcdd22","#fc1414","#106da8","#ec008c","#c6262c","#44911d","#00abbc","black"))+
  guides(color=guide_legend(""))+
  theme(legend.position="bottom", 
        axis.text.y=element_blank(),
        axis.ticks=element_blank())+
  labs(x="",y="",title="Figure 1",subtitle="Left-right")+
  facet_grid(variable~.)+
  coord_flip()
#> Warning: Removed 50 rows containing non-finite values (stat_boxplot).
#> Warning: Removed 1 rows containing missing values (geom_point).

I guess the reason for the 'Removed N rows containing non-finite values (stat_boxplot).' error message is, that the variable's class you use for the weight argument in aes() is character, but it should be (in your case) numeric. I have not looked for other issues in the code.

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.