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
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.
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With