R - Pie, X values ​​must be positive

I am new to R and have drawn some test country data in csv from the internet. I am currently fooling around a graph and have come across this error by creating a pie chart of unemployment in the world.

I released the following:

>values <- read.csv("D:\\test\\countrydata.csv")
>names(values)
 [1] "name"    "size"    "pop"    "unemployed" ...
>typeof(values$unemployed)
"integer"
>pie(values$pop)
Error in pie(values$unemployed) :
    'x' values must be positive
>pie(values$pop, na.rm=TRUE)
Error in pie(values$unemployed, na.rm=TRUE) :
    'x' values must be positive

The dataset I want to build is a set of integers, all of them are positive, 0 (thanks kim) or NA.

0 is not a problem when building integers, I tried

>pie(as.integer(c(0,1,2,3))

and it worked fine.

What am I missing here?

Thanks and respect,

BillDoor

+4
source share
1 answer

I do not have access to your data, but in my experience the following can help and is definitely worth a try:

pie(table(values$unemployed))

I would like to know if this solved your problem!

+3

All Articles