Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - Pie, X values must be positive

Tags:

r

I am new to R and drew some testdata about countries in a csv from the web. I am currenty fooling arround with plotting and encountered said error while creating a pie chart of the worlds unemployment.

i issued 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 plot is a set of integers, all of them are positive, 0 (thanks kim) or NA.

0 are not a problem when plotting integers, i tried

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

and it worked fine.

What am i missing here?

Thanks and Regards,

BillDoor

like image 395
billdoor Avatar asked Nov 25 '14 08:11

billdoor


People also ask

What is the value of R pie?

Pi is an inbuilt R constant whose value is 3.141593. The pi constant is a ratio of the circumference of a circle to its diameter.

How do you make a pie chart in R?

R Programming Language uses the function pie() to create pie charts. It takes positive numbers as a vector input. Parameters: x: This parameter is a vector that contains the numeric values which are used in the pie chart.

How do you show percentages on a pie chart in R?

Pie chart in R with percentage Note that the round function allows you to modify the number of decimals. An alternative to display percentages on the pie chart is to use the PieChart function of the lessR package, that shows the percentages in the middle of the slices.


1 Answers

I don't have access to your data but in my experience the following might help and is definitely worth a try:

pie(table(values$unemployed))

Would love to learn whether this solved your problem!

like image 136
vonjd Avatar answered Nov 12 '22 05:11

vonjd