0

The issue is pretty straightforward.

I am trying to generate a bar plot containing GDP per capita for several countries. The data is incomplete as some of the values are missing.

For instance, for year 1960, I only have data for 3 countries.

When I plot the data, the graph that is returned includes NAs, which I would like to exclude from the plot.

Please see an example below:

GDP <- ggplot(data, aes(country,1960)) + geom_bar(stat = 'identity', na.rm = T)

Please note that in this case, each column represents a year. The first column of the data frame consists of the name of the countries.

If it helps, please see the attached screenshot.

Bar plot returning NA values

Thanks.

J.C.
  • 140
  • 1
  • 7
  • 3
    a dput of your data would be nice, @J.C.? – hd1 Oct 22 '18 at 07:54
  • 1
    you can [remove `NA` rows from your dataframe](https://stackoverflow.com/questions/4862178/remove-rows-with-all-or-some-nas-missing-values-in-data-frame) ? – Ronak Shah Oct 22 '18 at 07:55
  • 1
    Related: [Remove unused factor levels from a ggplot bar plot](https://stackoverflow.com/questions/11403104/remove-unused-factor-levels-from-a-ggplot-bar-plot) – markus Oct 22 '18 at 07:57
  • 3
    `GDP <- ggplot(data[!is.na(data$country),], aes(country,1960)) + geom_bar(stat = 'identity', na.rm = T)` should do it – timat Oct 22 '18 at 08:02

0 Answers0