This question already has answers here:
population pyramid density plot in r
(5 answers)
Closed 9 years ago.
I have 11 data columns in a single data.frame, 10 of the columns are depth categories and one column contains one of two values (Day or Night).
Each row of data is populated with numeric values representing the percent of time spent in each depth category over a 4-hour period and has either Day or Night assigned to it in the Day_Night column indicating whether that 4-hour period was during the day or the night.
I would like to plot this data in a back to back histogram where each depth bin is listed vertically along the plot and values for the day are plotted in one histogram facing one way, while the values for the night are plotted facing the other way. I can't post a picture since I am new but to see what I mean just look at Figure 5 on page 8 of this publication.
EDIT: Here's the picture:
Thanks for the help!
You can use plotrix for example:
set.seed (123)
mm <- matrix (sample(seq(0,330,10),2000,rep=TRUE),ncol=2 )
ll <- lapply(as.data.frame(mm),
function(x)as.data.frame(table(cut(x,seq(0,330,10)))))
library(plotrix)
par(mar=pyramid.plot(ll$V1$Freq,ll$V2$Freq,
labels =ll$V1$Var1,
top.labels=c("NIGHT","","DAY"),
xlim=c(100,100),
main="Swimming depth",
lxcol="black",rxcol= "white",
gap=0,
do.first="plot_bg('pink')"))
Related
This question already has answers here:
Plot each column against each column
(2 answers)
Plot all pairs of variables in R data frame based on column type [duplicate]
(1 answer)
Closed 17 days ago.
I have the output of 3 different algorithms as a continuous vector. Instead of comparing their correlation 1 by 1, I would like to plot them all simuntaionusly in the same plot, but in different panels. The dataframe looks like this (but contains >10k ids):
df <- data.frame(id=1:5,
feature1=runif(5),
feature2=runif(5,min = 3,max=5),
feature3=runif(5, min = 5,max=8))
Ideally, the resulting plot should looks something like this:
I am fairly sure that there is some simple tidyr function, which expands my dataframe in such a way that I can simply use ggplot2 in combination with facet_grid, but I searched and coudn't find anything..
Any help is much appreciated!
Trying to create a plot showing the number of items (ex. pop_songs) released by year from a dataframe I have (ex. Music_Charts).
I have a year released column in my dataframe and can use that as the x-variable, but I don't know what I would use for the y-variable to show the boxplot since I have the Top 500 Ranked songs on the dataframe.
Well, based on your very general question, if you have a data frame column with the years for each song, you can easily get the count for that column using table.
table(dataframe$year_released)
That should give you the number of entries for every year, then you can plot them (i'm guessing that's what you need)
This question already has answers here:
Boxplot sees values that aren't there
(1 answer)
How to remove ticks and labels of dropped off factors in a box plot
(1 answer)
Closed 5 years ago.
You can see my plot in this link.
I want to remove the first three points from the x axis, so I only display data from "2.31-52k", "1.52-100k", "3.18-31k", "4.<18k", "0.>100k". And not -1.0,-3.1 etc.
I have managed to remove the data to produce this graph, by creating a subset in dAll$income and assigning it to a new data frame with the following code.
new_df = subset(dAll, subset = dAll$income %in% c("2.31-52k", "1.52-100k", "3.18-31k", "4.<18k", "0.>100k"))
However when I plot this, the values remain on the x axis.
This question already has answers here:
Convert continuous numeric values to discrete categories defined by intervals
(2 answers)
Closed 6 years ago.
I have a data frame in R that has a personal ID, an income and some other variables. I would like to add a new column to this data that categorises people in to which income group they fit in to (0-24,999, 25,000-49,999, 50,000-74,999, 75000-99,000, etc).
I then want to be able to make frequency tables of this data compared with some of the other variables (eg: weekly hours worked, age).
I should be fine to figure out the latter of these problems, but I am having trouble figuring out how to categorise my data. Any help would be greatly appreciated.
Thank you.
We can use cut or findInterval to group the "Variable"
gr <- cut(df1$Variable, breaks = c(0, 24999, 49999,74999,99999, Inf))
Then, use table to get the frequency count
table(gr, df1$age)
This question already has answers here:
How to create grouped barplot with R [duplicate]
(1 answer)
plotting grouped bar charts in R
(3 answers)
Closed 3 years ago.
I have a data table with two small columns.
I want to do a pairwise comparison between the values. The first column is results of one test and the second of another test. So I want a barplot where the first pair of bars show value [1,1] and next to it [1,2] then [1,2] besides [2,2] and so on.
I have 20 values (10 in each from 10 instances) and want 20 bars in one plot. I have no category variable but I want to preserve the order in which they appear in the column (each result corrosponds to an instance). Hence 20 values represented by 20 bars.
Hope you can help.
Edit: Sry for the bad explanation.
Based on your vague question I think this is what you want. Here is a quick example you can use to get your results:
counts <- table(mtcars$vs, mtcars$gear)
barplot(counts, main="Car Distribution by Gears and VS",
xlab="Number of Gears", col=c("darkblue","red"),
legend = rownames(counts), beside=TRUE)
Source: http://www.statmethods.net/graphs/bar.html