I have a data frame (df) that contains time (five min intervals) and number of animals that passes by at three different locations. Countings starts and ends at the same time for all three places. They are passing by the three places at different times; first place1, second place2 and third place3 due to their alignment in space.
Today I get:
Number of animals on the y-axis and time on the x-axis (where there are three separate groupings like I want). However, time starts over again for each of the three groupings (thus the x-axis looks like this (start-end, start-end, start-end).
What I want:
A plot with number of counts on the y-axis, and time on the x-axis (from start to end of counting). Thus there will be a "displacement" of number of animals (possible fewer as well) as time goes by.
My code today is:
barplot(df$nr.animals, names.arg = df$time, xlab="Time", ylab="Number of animals counted")
How can I get this data into a barplot with time on the x-axis (without the time starting at the beginning again for each new place)?
EDITED:
see picture for some of my dataset:
time=time, pos has three different values: mmys1, mmys_c1 and mmys_c2, which stands for the three different places, nr.bats.dir1 = number of animals counted in that specific time interval
see picture of the structure of my dataset:
time has factor format, nr,bats.dir1 has integer format
thus my code is actually like this
barplot(df$nr.bats.dir1, names.arg = df$time, xlab="Time", ylab="Number of bats counted")
Thanks!
Related
I am trying to make a line graph, that will plot data over 4x time points for different conditions. Right now, I have the conditions as one variable, but the values for each time point are each in their own variable column.
I can't figure out how to best graph it such that the y-axis shows each condition, and the x-axis shows the "score" over each time point.
How do I graph variables that represent different time points?
I am making separate histograms of travel distance per departure hour. However, for making further calculations I'd like to have the value of each bin in a histogram, for all histograms.
Up until now, I have the following:
df['Distance'].hist(by=df['Departuretime'], color = 'red',
edgecolor = 'black',figsize=(15,15),sharex=True,density=True)
This creates in my case a figure with 21 small histograms.
With single histograms, I'd paste counts, bins, bars = in front of the entire line and the variable counts would contain the data I was looking for, however, in this case it does not work.
Ideally I'd like a dataframe or list of some sort for each histogram, containing the density values of the bins. I hope someone can help me out! Thanks in advance!
Edit:
Data I'm using, about 2500 columns of this, Distance is float64, the Departuretime is str
Histogram output I'm receiving
Of all these histograms I want to know the y-axis value of each bar, preferably in a dataframe with the distance binning as rows and the hours as columns
By using the 'cut' function you can withdraw the requested data directly from your dataframe, instead of from the graph. This is less error-sensitive.
df['DistanceBin'] = pd.cut(df['Distance'], bins=10)
Then, you can use pivot_table to obtain a table with the counts for each combination of DistanceBin and Departuretime as rows and columns respectively as you asked.
df.pivot_table(index='DistanceBin', columns='Departuretime', aggfunc='count')
I have an excel scatter plot with 5 different data series on single chart. First 4 series are working well. When I want to add a new series with similar x-axis data (0.0, 0.4, 0.9 .. ) the plot is displayed with x-axis values as 1,2,3 but not as the data specified.
Changing the chart types did not help. Not sure how can I get the x-axis as data but not as sequential numbers. Any help is appreciated. Thanks.
Added the screenshot of chart and its xaxis data. The values are in number format only just as data for other series. Everytime I am adding a new series on to this, its starting with one number later.... (1,2,3...) next series x axis at (2,3,4....) but not with real x values as selected.
Solved it my slef... The problem is X-axis range is for 18 cells and all the cells had formula with IF condition... When I removed the IF condition, x-axis worked well as numbers
The IF condition I used was "=IF(A10<>"",B10=A10-A4,""), for some reason excel chart considered this as some text and populated the x axis as 1,2,3 but not as the values specified.
R has some built in datasets, namely I'm using "lynx" and "LakeHuron" which are of different lengths. "lynx" contains data on annual lynx trappings from 1821-1934, and "LakeHuron" contains annual water level from 1872-1975.
I need to plot LakeHuron data on the y-axis, and lynx data on the x-axis, but only for the years 1875-1934 inclusive. I created two vectors:
lynx.years = c(lynx)
huron.years = c(LakeHuron)
I am stuck at the point of trying to only make a plot for the specified year range. Can someone help me figure out how to plot the data from the two vectors for only the years 1875-1934?
Thank you!
1) The question did not specify what sort of plot was desired so assume it is a two panel plot with one series in each panel with years on the X axis such that only the range of years mentioned is shown. That range of years is the intersection of the years of the two series so:
plot(na.omit(cbind(LakeHuron, lynx)))
Drop the na.omit if you want to plot the entirety of the two series.
2) If what is wanted is to rescale the two series so that their shapes can be shown on a single panel despite vastly different ranges:
ts.plot(scale(na.omit(cbind(LakeHuron, lynx))), col = 1:2)
Again, we could drop the na.omit if the entire series were desired.
3) If what is wanted is to plot one vs. the other then:
plot(unclass(cbind(LakeHuron, lynx)))
I am trying to plot the Operating Cash flow of BBBY (Bed Bath & Beyond) and the stock price.
2x Problem! 1) The price variable is daily, and operating cash flow variable I have is annual. When I plot both charts the graph never lines up correctly. How do I plot two time series, of different frequencies and have the annual operating cash flow data points line up to the daily variable on the chart. 2) How do I get the axis for operating cash flow only on the right of the chart and the stock price only on the left. Everytime I try to graph both variables the operating cash flow gets pasted on top of the existing stock price and you end up with a jumbled left axis. Help!!! (Thank you )
setInternet2(TRUE)
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)
library("quantmod")
getSymbol("BBBY",from="1-1-2000")
data1=fund.data("BBBY",30,"annual",1)
operatingcash=as.numeric(gsub(",","",data[169,]))
date.year=seq(as.Date("1994-01-01"),length=22,by="years")
plot(BBBY)
par(new=T)
axis(4)
plot(date.year,operatingcash,type="l",axis=4)
First, plot the main series:
plot(BBBY)
Then reset the Y limits by changing values 3 and 4 in par()$usr:
par(usr="[<-"(par()$usr,3:4,range(operatingcash)))
Now add the operating cash. Note conversion to as.POSIXct since that's what the time
series plot sets the x-axis with:
lines(as.POSIXct(date.year),operatingcash,col="red")
And now add the right axis and label:
axis(4,col="red",col.axis="red")
mtext(4,col="red",text="Operating Cash",line=3)
Giving:
The operating cash line is now chopped because its data goes back to 1994. You can also see that the data points line up with the year starts.
The only change to your example I did was to call the data data and not data1, and use getSymbols and not getSymbol.