Show Up only one Piece of a Pie Chart - r

In plotrix I would like to make a pie chart like this:
pieval<-c(2,4,6,8)
pielabels<- c("We hate\n pies","We oppose\n pies","We don't\n care","We just love pies")
lp<-pie3D(pieval,radius=0.9,labels=pielabels,explode=0.1,main="3D PIE OPINIONS")
And I would like only the pie piece corresponding to "We just love pies" to show up, which should give something like this:
But of course I fail to make it because I use this code:
lp<-pie3D(pieval[4],radius=0.9,labels=pielabels[4],explode=0.1,main="3D PIE OPINIONS")

If you just want to draw one 3d tilted pie sector, use draw.tilted.sector.
Display a 3D pie sector
Description:
Displays a 3D pie sector.
I did experiment with setting the colour and border colour of pie segments to NA but I couldn't get rid of the shading.
But as expressed in comments, only use 3d pies if you are making a comment about how poor 3d pie charts are.

I used the draw.tilted.sector suggested by this answer.
I managed to get rid of all the shading, borderlines and sectors by making them white.
pieval <- c(2,4,6,8)
pielabels <- c("","","","We just love pies")
#make everything white
lp <-pie3D(pieval,radius=0.9,labels=pielabels,explode=0.1,
main="3D PIE OPINIONS", col= "white", shade =0, border="white")
#draw the sector
draw.tilted.sector(start = (24/20)*pi, end = 2*pi,
radius= 0.9, explode =0.1, col= "purple")

Instead you can use sector.order to display any sector according to your choice. For this case you can use
pie3D(pieval, radius=2, labels="We hate\n pies", explode=0.1, main="3D PIE OPINIONS", col=c("brown", "#ddaa00", "pink", "#dd00dd"), sector.order = 4)

Related

Fill region below stairs plot with a particular transparency using Makie.jl in Julia

I'd like to fill the region below a stairs!() plot (between the stairs and the x axis) in order to get something like the gray area in the image, but with a specific % transparency.
A somewhat hacky way (digs into the stair plot to get the graphed points):
function stairpts(s)
pts = s.plots[1].converted[1][]
[p[1] for p in pts], [p[2] for p in pts]
end
s = stairs!(xs, ys, step=:post)
xs′, ys′ = stairpts(s)
band!(xs′, 0*ys′, ys′, color=(s.color, 0.25)) # 0.25 alpha
Creating a recipe for this
type of plot is probably better.
What you show looks like multiple barplots or histograms (hist!() function or barplot!() function) with transparency allowing see-through overlap. Could you do this using barplot or hist! (depending on your data) instead of stairs!? If you want the barplots to be more uniform in outline, you could make the outline strokewidth thicker and the same strokecolor as the bars.

Adding sample size data to pie chart in R (mapplots package)

I have been able to plot several pie charts overtop a map, representing different populations. However, what I would like to do is somehow represent the sample size for each of the pie charts, as its differs between population. I have a loop to add each population present in the dataset as a pie chart:
map("worldHires", xlim=c(-140, -110), ylim=c(48, 64), col="lightgray", fill=TRUE)
points(x=-120.43,y=50.34, col="black", pch=19)
segments(x0=dataframe$Long, y0=dataframe$Lat, x1=dataframe$Long2, y1=dataframe$Lat2, col="black")
add.pie(z=c(2, 5, 6),x=-122.43,y=52.34,labels="",radius = 1)
for(i in 1:nrow(dataframe))
{
add.pie(as.integer(dataframe[i,c("Cat1","Cat2", "Cat3")]*100),
x=dataframe$Long2[i],y=dataframe$Lat2[i],labels="",radius = 0.08,
col=c("red","blue", "green"))
}
title(ylab="Latitude")
title(xlab="Longitude")
box(which="plot")
I would like to add the sample size data (dataframe$n) somehow. I've seen examples of scaled radius pie charts, which could work here, or even just adding the sample size above the pie chart. To get the sample size above the pie chart I tried adding 'main=dataframe$n' between labels and radius in the add.pie portion of the code, but this did not work. Does anyone have any ideas on how to add this to my script? Thank you.
The size of each pie is plotted according each value in your dataframe. The good dataframe for this has a stations as rows and the class type are columns

How can I make legend next to my piechart in R?

I have made a piechart in R with the next code:
#make slices
slices <- c(19, 26, 55)
# Define some colors
colors <- c("yellow2","olivedrab3","orangered3")
# Calculate the percentage for each day, rounded to one decimal place
slices_labels <- round(slices/sum(slices) * 100, 1)
# Concatenate a '%' char after each value
slices_labels <- paste(slices_labels, "%", sep="")
# Create a pie chart with defined heading and custom colors and labels
pie(slices, main="Sum", col=colors, labels=slices_labels, cex=0.8)
# Create a legend at the right
legend("topright", c("DH","UT","AM"), cex=0.7, fill=colors)
But I want the legend next to my piechart. I have also tried the following code: legend("centreright", c("DH","UT","AM"), cex=0.7, fill=colors).
But this does not give me a legend next to my pie chart.
Which code do I have to use to make a legend next to my pie chart in the middle?
You can play with the x and y argument from legend (cf ?legend):
legend(.9, .1, c("DH","UT","AM"), cex = 0.7, fill = colors)
However, a pie chart may not be the best way to represent your data, because our eye is not very good in assessing angles. The only usecase where a pie chart seems reasonable to me is when comparing 2 categories, because due to watches we can assess these proportions rather easily.

Is there a way to change the thickness and color of the curves in the plot using wireframe of lattice in R?

I am using the wireframe in lattice package of R to plot a 3D data.
I think it is because there're too many data points so the plot looks a little messy.
Is there a way to make the connecting curves (between the yellow and red blocks) in the plot more of light color or thinner?
You can change the color of the lines, but I think the width is already minimal. Here is an example:
wireframe(volcano, drape =T, col="grey",
aspect = c(61/87, 0.4),
light.source = c(10,0,10))

Preserving values and labels order in pie chart

I'd like to draw a pie chart where the order of values and labels must be preserved. How could I produce it?
It seems that by default R can control for alphabetical and clockwise order.
I addition, I'd like to add more information to the chart by adding arrows connecting one point to the other of the chart, like from ABC to ZXR, is it any possible?
# Simple Pie Chart
slices <- c(12,11,11,8,6,2,5,3)
lbls <- c("ABC", "DEF", "GPH", "ZXR", "O", "MN", "TS", "ZY")
pie(slices, labels = lbls, main="ranking disk")
Thanks,
Eve
The following will create a pie chart with the labels in the order you posit them, starting at 12 o'clock and going around clockwise:
pie(slices, labels = lbls, clockwise=TRUE, init.angle=90, main="ranking disk")
You can adapt the clockwise and init.angle parameters.
Unfortunately, pie does not return the coordinates of labels or slices, but you can add arrows by hand if you adapt the coordinates as you need them:
arrows(.6,.6,-.6,-.4)
However, you do know that pie charts are horrible ways of presenting information, right? The following part of the help page ?pie is well worth quoting in full:
Pie charts are a very bad way of displaying information. The eye
is good at judging linear measures and bad at judging relative
areas. A bar chart or dot chart is a preferable way of displaying
this type of data.
Cleveland (1985), page 264: “Data that can be shown by pie charts
always can be shown by a dot chart. This means that judgements of
position along a common scale can be made instead of the less
accurate angle judgements.” This statement is based on the
empirical investigations of Cleveland and McGill as well as
investigations by perceptual psychologists.

Resources