Domanda

Iam relatively new to R and could not figure this out myself.

I have a frequency histogram and I am trying to multiply the frequency of each bin (Y axis) with the values on the X axis.

The Code for my histogram looks like this:

logarea <- log10(wildfires$areacalc)  #to make x-axis logarithmic
hist(logarea, breaks="FD", main="Frequency of Fire Size", xlab="Log10 of Area Burned [m2]",
yaxt="n",xlim=c(5,10), cex.main=0.8, cex.axis=0.8, cex.lab=0.75, col="grey47", border = "seashell3")
axis(2, at=seq(0, 1100, by = 200), las = 2, cex.axis=0.8)

Thank you!

È stato utile?

Soluzione

Try this:

h <- hist(logarea,breaks="FD")
product <- with(h,mids*counts)

In addition to plotting a histogram, hist(...) returns a list of values. h$counts is the frequency (number of observations) in each bin, and h$mid is the midpoint value of the bin. So I think this is what you're looking for. See the documentation for more information.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top