Error In Barplot.default Incorrect Number Of Names
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to plot summaries of a table in bar chart up vote -1 down vote favorite I have a table of SNPs and the information about the corresponding gene: Gene ID, Gene type and Gene Name: SNP Gene ID Gene type Gene Name 1 rs10876864 ENSG00000123411.10 protein_coding IKZF4 2 rs10876864 ENSG00000123411.10 protein_coding IKZF4 3 rs10876864 ENSG00000123411.10 protein_coding IKZF4 4 rs10876864 ENSG00000123411.10 protein_coding IKZF4 5 CNVR2845.57 ENSG00000196126.6 protein_coding HLA-DRB1 6 CNVR2845.57 ENSG00000196126.6 protein_coding HLA-DRB1 7 CNVR2845.57 ENSG00000196126.6 protein_coding HLA-DRB1 8 CNVR2845.57 ENSG00000196126.6 protein_coding HLA-DRB1 9 rs6030897 ENSG00000201372.1 snRNA U6 10 rs6030897 ENSG00000201372.1 snRNA U6 11 rs6030897 ENSG00000201372.1 snRNA U6 I want to plot a bar chart of the total # of SNPs to see how many of the SNPs are protein_coding or snRNA or etc. This is my code so far: barplot(as.matrix(data1), main="SNP", xlab="Gene type", ylab= "Total SNP", names.arg=c("protein_coding","snRNA","pseudogene","antisense","lincRNA",""), border="blue", density=c(10, 20, 30, 40, 50)) But i'm getting an error saying: Error in barplot.default(as.matrix(data1), main = "SNP", xlab = "Gene type", : incorrect number of names In addition: Warning messages: 1: In apply(height, 2L, cumsum) : NAs introduced by coercion 2: In apply(height, 2L, cumsum) : NAs introduced by coercion 3: In apply(height, 2L, cumsum) : NAs introduced by coercion 4: In apply(height, 2L, cumsum) : NAs introduced by coercion r graph bar-chart share|improve this question edited Jun 20 '13 at 10:27 Michele 4,2752050 a
♦ ♦ | Report Content as Inappropriate ♦ ♦ bar plot issues Hi! I have 2 problems in drawing a stacked bar plot: (1) This is a stacked bar plot with more than 100 bars next to each other. So there should not be names at the bottom of the bars because the bars are too narrow. I tried arg.names=NULL but that does not work because R uses the row names from the data.frame. How can I suppress the placing of names below the bars? (2) The position of the legend http://stackoverflow.com/questions/17209832/how-to-plot-summaries-of-a-table-in-bar-chart is problematic. The legend is big, more than 20 items. It overlays the bars themselves and makes the plot unreadable. I would like to move it outside the plot and have tried legend("topleft") but R complains about missing information. Here is what I have so far ######################################################## barplot(t(file.codes), + beside = FALSE, + col = rainbow(ncol(file.codes)), names.arg=NULL, http://r.789695.n4.nabble.com/bar-plot-issues-td3922378.html + legend = FALSE, + main = "Presidential documents - Codes per document", + xlab = "document", ylab = "number of codings") ####################################################### Any ideas? Thanks, Henri-Paul -- Curriculum & Instruction Texas A&M University TutorFind Learning Centre Email: [hidden email] Skype: hindiogine Website: http://people.cehd.tamu.edu/~sindiogine______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. Uwe Ligges-3 Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: bar plot issues On 20.10.2011 18:03, Henri-Paul Indiogine wrote: > Hi! > > I have 2 problems in drawing a stacked bar plot: > > (1) This is a stacked bar plot with more than 100 bars next to each > other. So there should not be names at the bottom of the bars because > the bars are too narrow. I tried arg.names=NULL but that does not > work because R uses the row names from the data.frame. > > How can I suppress the placing of names below the bars? It is the argument *names.arg* and it ha
this? BioStatMatt11-08-2006, 11:59 AMIt will be difficult to determine what you are doing wrong without seeing the command you used https://github.com/allr/timeR/blob/master/src/library/graphics/R/barplot.R and the output. Do you get errors? naivesincerity11-08-2006, 12:11 PM>barplot(Election8387929701,space=c(0,0.5),beside=TRUE,col=c("red","blue","yellow"),legend.text=c("Labour","Conservative","Liberal Democrats"),ylim=c(0,50),names.arg=year,ylab="Percentage of vote") naivesincerity11-08-2006, 12:13 PMBefore that was: > Election01=c(41.41,35.23,19.42) error in > Election83=c(26.94,45.98,14.36) > Election87=c(29.51,46.24,13.58) > Election92=c(33.93,45.46,19.18) > Election97=c(43.55,33.69,17.95) >year=c(1982,1987,1992,1997,2001) >Election8387929701=rbind(Election83,Election87,Election92,Election97,Election01) naivesincerity11-08-2006, 12:18 PMBut even when it does respond with a '+' sign, as though the plot has been drawn, with no error message, I can't find the plot on the error in barplot.default terminal naivesincerity11-08-2006, 12:42 PMError in barplot.default(Election9701, space = c(0, 0), beside = TRUE, : incorrect number of names In addition: Warning message: parameter "legend.txt" couldn't be set in high-level plot() function Got this message BioStatMatt11-08-2006, 05:42 PMtry changing the "rbind" to "cbind" like this: Election01=c(41.41,35.23,19.42) Election83=c(26.94,45.98,14.36) Election87=c(29.51,46.24,13.58) Election92=c(33.93,45.46,19.18) Election97=c(43.55,33.69,17.95) year=c(1982,1987,1992,1997,2001) Election8387929701=cbind(Election83,Election87,Election92,Election97,Election01) barplot(Election8387929701,space=c(0,0.5),beside= TRUE,col=c("red","blue","yellow"),legend.text=c("Labour","Conservative","Liberal Democrats"),ylim=c(0,50),names.arg=year,ylab="Perc entage of vote") If you indeed wanted groups of bars according to political party, it looks like you have used names.args and legend.text in the incorrect places. A legend identifies a particular bar within a group, the names.arg argument holds a vector of names for the groups. You also have some funky colors. Try this code: Election01=c(41.41,35.23,19.42) Election83=c(26.94,45.98,14.36) Election87=c(29.51,46.24,13.58) Election92=c(33.93,45.46,19.18) Election97=c(43.55,33.69,17.95) year=c(1982,1987,1992,1997,2001) Election8387929701=rbind(Election83,Election87,Election92,Election97,Election01) barplot(Election8387
Sign in Pricing Blog Support Search GitHub This repository Watch 13 Star 7 Fork 2 allr/timeR Code Issues 0 Pull requests 0 Projects 0 Pulse Graphs Permalink Branch: master Switch branches/tags Branches Tags master vendor Nothing to show R-301 Nothing to show Find file Copy path timeR/src/library/graphics/R/barplot.R Fetching contributors… Cannot retrieve contributors at this time Raw Blame History 202 lines (183 sloc) 6.81 KB # File src/library/graphics/R/barplot.R # Part of the R package, https://www.R-project.org # # Copyright (C) 1995-2012 The R Core Team # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # A copy of the GNU General Public License is available at # https://www.R-project.org/Licenses/ barplot <- function(height, ...) UseMethod("barplot") barplot.default <- function(height, width = 1, space = NULL, names.arg = NULL, legend.text = NULL, beside = FALSE, horiz = FALSE, density = NULL, angle = 45, col = NULL, border = par("fg"), main = NULL, sub = NULL, xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, xpd = TRUE, log = "", axes = TRUE, axisnames = TRUE, cex.axis = par("cex.axis"), cex.names = par("cex.axis"), inside = TRUE, plot = TRUE, axis.lty = 0, offset = 0, add = FALSE, args.legend = NULL, ...) { if (!missing(inside)) .NotYetUsed("inside", error = FALSE)# -> help(.) if (is.null(space)) space <- if (is.matrix(height) && beside) c(0, 1) else 0.2 space <- space * mean(width) if (plot && axisnames && is.null(names.arg)) names.arg <- if(is.matrix(height)) colnames(height) else names(height) if (is.vector(height) || (is.array(height) && (length(dim(height)) == 1))) { ## Treat vectors and 1-d arrays the same. height <- cbind(height) beside <- TRUE ## The above may look strange, but in particular makes color ## specs work as most likely expected by the users. if(is.null(col)) col <- "grey" } else if (is.matrix(height)) { ## In the matrix case, we use "co