How to change info in a histogram in r? - r

I'm trying to build a histogram in which the X-axis shows each case I'm working with (my matrix's info includes the murders' resolution rate for different police stations in one city for a year), each police station, and the Y-axis would show the resolution rate (from 0 to 1). So, there would be 51 bars, one for each police station, and each one should reach one of those rates from 0 to 1.
But when I run hist with my matrix, the X-axis displays resolution rates and the Y-axis displays the frequency, the number of police stations that reach each resolution rate.
How can I get the result I wrote before? This is the code I'm using:
anobase<-matrix(CResolucion[seleccion_ano==2018], length(seleccion_estado), 1)
rownames(anobase) <- seleccion_estado
colnames(anobase) <- 2018
hist(anobase)
(and, yeah, I'm new at using R)
So, that's the plot. As you see, the X-axis displays values from 0 to 1. These values represent the resolution rate said before (result from dividing solved murders by the total of murders registered). The Y-axis on the other hand displays a frequency from 0-15. Then, each bar shows how many cases have each resolution rate. What I want to do is show in the X-axis each police station, so each bar would be a police station, and they should reach that resolution rate from 0-1 (Y-axis). I hope I'm being clear.

You don't want a histogram; you want a column or bar chart. Histograms summarize the distribution of a single continuous variable; column charts compare values of a continuous variable across categories (here, police stations).
You haven't posted a reproducible example, so I can't tell exactly what's going on with your data. Let's assume, though, that you have a vector of resolution rates called rates and a vector of station names associated with those rates called stations. In base R, you could then create a column chart with barplot(rates, names.arg = stations).

Related

What are the names of the graphs used in the NAPLAN? Anyone know how to plot them?

In Australia we have a test for students called NAPLAN.
The results are provided in a sort of band graph mixed with a box and whisker.
Does anyone know what they are called?
They are good because they show total range, Where the student falls in the band. What the national average is and what the students class average is.
essentially 4 data points on 1 graph.

pixelwise rescaling of a time series using cumulative distribution function matching

I'm using R and I have a raster stack of surface soil moisture measurements from a radiometer on fixed on an observation tower. These data are daily values going back 10 years.
I also have another raster stack of satellite microwave measurements of soil moisture over a larger area going back 25 years. Both sensors have similar frequencies.
On a per-pixel basis, I would like to use a linear cumulative distribution function matching that rescales the satellite data against the tower data so that it would result in a longer time series of rescale satellite data.
This point is to correct for systematic differences between the soil moisture values and extend the time series. This is similar to what was done in the figure below where they matched the AMSR-E (blue plot) and ASCAT (red plot) data to Noah data (black plot).
Does anyone know how to implement this in R? Or at the very least help me get started? I've scoured the Internet and this website without success.

Interpretation of a graph created by the R package seas

I am relatively new to R studio and R in general, I am not even sure if this is the right place to ask this question. I was instructed to draw a graph showing seasonality using daily rainfall over a number of years. I need help more in interpreting the graph than in plotting it.
There is an example already in R using mscdata that I was able to replicate using my own data, the code for the example is as below. Any help with what this graph means or explains will be greatly appreciated.Thank you
install.packages(seas)
library(seas)
data(mscdata)
dat <- mksub(mscdata, id=1108447)
dat.ss <- seas.sum(dat, width="mon")
x<-mscdata
# Structure in R
str(dat.ss)
tail(mscdata)
# Annual data
dat.ss$ann
# Demonstrate how to slice through a cubic array
dat.ss$seas["1990",,]
dat.ss$seas[,2,] # or "Feb", if using English locale
dat.ss$seas[,,"precip"]
# Simple calculation on an array
(monthly.mean <- apply(dat.ss$seas[,,"precip"], 2, mean,na.rm=TRUE))
barplot(monthly.mean, ylab="Mean monthly total (mm/month)",
main="Un-normalized mean precipitation in Vancouver, BC")
text(6.5, 150, paste("Un-normalized rates given 'per month' should be",
"avoided since ~3-9% error is introduced",
"to the analysis between months", sep="\n"))
# Normalized precip
norm.monthly <- dat.ss$seas[,,"precip"] / dat.ss$days
norm.monthly.mean <- apply(norm.monthly, 2, mean,na.rm=TRUE)
print(round(norm.monthly, 2))
print(round(norm.monthly.mean, 2))
barplot(norm.monthly.mean,
ylab="Normalized mean monthly total (mm/day)",
main="Normalized mean precipitation in Vancouver, BC")
# Better graphics of data
dat.ss <- seas.sum(dat, width=11)
image(dat.ss)
This code gives a graph showing sample quartiles, annual rainfall but I don't really know what it means. Any help whatsoever will be appreciated
The Graph using the package seas is as below
Plot
I'll start with the top left graph :
You've probably guessed that each row is a year (as shown by the Y-axis) while day groups/months of the year are X-axis. The color of each box of the heatmap is proportionally darker according to the mm's worth of rain in that day group, with the scale being displayed on the far right. I assume the red X's mean missing values.
Top right is like a barplot with the sum of rainfall each year (row), just continuously plotted. The red bar should be the average precipitation overall (not sure about the orange one).
Bottom left is a bit more tricky. Think of it like you reordered the rows in each column to have the heaviest rainfall of the day group at the top (forgetting about the year info here). The Y-axis shows the quantiles. The quantiles' respective values change for each day group, so the lines you see on top of the plot indicate key rainfall values in mm (4,6,8,10,12). Indeed, If you look at the 2mm line (lowest one), you'll see that in January, about 20% of rainfalls (across all years) are below this threshold, while in the end of July, over 80% are below 2mm (expect less rainfall in the summer).
Lastly, bottom right is similar to the one above it. It's the sum of all rows, referring to the quantiles rather than years this time, resulting in the staircase pattern.
You'll notice that since the scale of the plot is the same as the one showing the average per year, the top of the staircase is outside of the plot...
Hope I made that clear enough.

Kibana histogram with a bucket size of 1 on the x axis

I've a bunch of data in ES that I'm looking to visualize in Kibana. I have 1000 different products and a percentage stock level of each one, updated every minute. In my index I thus have productcode and stocklevel. In any given period (e.g. last hour) I'd like to know which products have dipped below 80% of maximum stock level
In Visualize, I've set the Y axis to be MIN(StockPercentage) and the X axis to be a Histogram of the product code. It works, but kibana is automatically choosing the bucket size for the x axis and on this particular graph it's somewhere around 25 product codes per bucket. I thus get the minimum stock level of any of the 25 products in the bucket which does help narrow it down, but I was hoping for a graph that can tell me with an aggregation precision per product (i.e. no aggregation)
I've also looked at doing a Range agg of the ProductCode but it looks like i'll have to add 1000 ranges (1 to 2, 2 to 3...) to get the product codes to show up, and that's a lot of ranges
How can I make a graph that doesn't do any aggregation of product codes and just draws a bar line per product code?

Ranking of genotype plot based on temperature of canopy

I am working on crop water stress monitoring. I have thermal images of different crop genotypes of same day. I would like to plot temperature values for genotypes as black and white horizontally spaced diagram as shown in image that shows black colour as higher temperature and white colour as low temperatures. Pleas help me. The link of the demo data for 20 genotypes is given below-
Demo Temperature data for 20 genotypes (First column is Genotype No., second column is min temp and third column is max temp.)
A similar figure from different study is attached herewith.
This type of plots can be simply created using MS excel.
Select the data arranged in 2D matrix, Insert (on the main Excel bar), Chart, Surface, contour. If it defaults to the wrong sort of surface chart, click on Change chart type, surface, contour.
This info was provided by
Dr. Hamlyn G Jones,
Emeritus Professor of Plant Ecology,
Division of Plant Sciences, University of Dundee.

Resources