Balloons in R: Strange Empty 1st Column

The following code creates Barplot in R. However, the first column is empty. I don’t understand why ... There are no NA values ​​in my dataset. How can I remove the space between the Bayview Column and the Y-Axis?

# 2. Bar Plot for Police District barplot(xtabs(~sample$PoliceDistrict), main="Police District Distribution of Incidents", xlab="Number of Incidents in Police District", ylab="Frequency", col=rainbow(nlevels(as.factor(sample$PoliceDistrict))), las=2, # cex.lab=0.50 This is for the x-axis Label, cex.names = 0.45 ) 

Here is the result of Barplot with a 1st empty column:

enter image description here

+3
formatting r bar-chart
source share
1 answer

You have an empty factor level floating around, for example:

 x <- factor(c("One","One","Two","Two","Two"), levels=c("","One","Two") ) levels(x) #[1] "" "One" "Two" barplot(table(x)) ## EXTRA BAR PLOTTED x <- droplevels(x) # ?droplevels # The function 'droplevels' is used to drop unused levels from a # factor or, more commonly, from factors in a data frame. levels(x) #[1] "One" "Two" barplot(table(x)) ## FIXED 
+1
source share

All Articles