I want to generate a plot in which I'm capable of visualising the distribution of a given variable in space.
Let's say I want to know how the values of frequency bandwidth (Hz) of a bird's song are spread in space.
I tried with scatterplot3d. But I'm think this is not right.
x<-a vector with easting coordinates
y<-a vector with northing coordinates
z<-a vector with the bandwidth values (in Hz)
Then I do:
scatterplot3d(x,y,z)
Should "z" be a coordinate or can I use it as a vector of values of a given variable?
Thanks in advance!
I did it with scatterplot3d.
scatterplot3d(Hypo$Easting,Hypo$Northing,Hypo$Song_Dur,angle=118,color="red",pch=16,highlight.3d=TRUE,xlab="Easting",ylab="Northing",type="h",lwd=1)
Where Hypo$Easting==x, Hypo$Northing==y and Hypo$Song_Dur==z(variable).
Related
I have taken photos of a bird nesting area and have marked positions of earch bird on the photo. Resulting data is a list of X and Y positions. I transformed pixel data to meters data.
I want to calculate how many of counts are there in squares of 1m2. I was able to get what I looked for graphically with geom_bin2d but I would like to extract the value of each of the squares.
Any functions that would do this? or methods to extract data from geom_bin2d?
Thank you very much!
I have found few functions (density, bkde2D) but they are related to Kernel density estimate, which doesn't seem to fit the same values with geom_bin2d.
I'm rather new to programming and the site so let me know if I screw up on this explanation.
I have a rather long series of x, y coordinates representing a character in 2d space. Let's say that space is 200 x 400. I want to represent the amount of time the character is in each x, y coordinate by means of a pretty chloropleth.
I want to use heatmaply for this because I think the output is pretty and I want my audience to be able to zoom in on the data. It isn't really meant to do density estimation (I think?) so I'm trying to work around it.
I suppose the way to do this is to fill a 200x400 dataframe with counts of the number of occurrences of each x, y coordinate in the data at each x, y coordinate in the frame. Essentially, to build a 2d map out of the data frame and impose the counts upon it
So, I suppose my questions are:
1). How do I get the count of each unique x, y coordinate in my set
2). How might I pass those counts easily to the matching x, y cell in my 200x400 dataframe full of zeroes?
This seems like it should be easy but I can't seem to figure it out! I'm a novice to r and can't see the shape of what I need to do.
You can use the table function to get your matrix of counts.
table(X,Y)
X and Y should be columns of coordinates.
Output based on some sample data
Hi? I have a data of seedlings distribution which contains species types, X and Y coordinates in UTM. I want to create a point pattern by their X & Y coordinate location with the help of ppp() function in spatstat package. I tried it with following 2 ways:
p.patt <- ppp(mydata$X, mydata$Y)
p.patt <- ppp(mydata$X, mydata$Y, owin(c(100,131), c(100,130)))
But there is a “Warning message: 435 points were rejected as lying outside the specified window” for both of them.
I guess this is related to ranges of X and Y coordinates that should be specified in this code in c(…), c(…). I checked the range of X &Y and R gave me following ranges:
for X: 368615 and 368746,
for Y: 4587355 and 4587485
When I plot the data, a shape of the plot looks like "tilted rombo". I don't know if it is help.
Here I have just randomly chosen tried some numbers: 100 & 131 & 130. I couldn’t find any information how to set them online.
So my question is how I can use these ranges of coordinates to set observation window geometry of point patterm in spatstat package in R?.
Thank you very much in advance!
The numbers in the owin call are not the width and height of the window; they are the X and Y coordinates of the corners of the window.
Since the range of X coordinate values of the data points is from 368615 to 368746, the window needs to contain this range, at least. Similarly the range of Y values must be contained in the window. The minimal window that will not give a warning is
p.patt <- ppp(mydata$X, mydata$Y, owin(c(368615,368746), c(4587355,4587485)))
or equivalently
p.patt <- ppp(mydata$X, mydata$Y, c(368615,368746), c(4587355,4587485))
But this is just the minimal window that is acceptable; for a proper analysis, you need information about the survey region. If it is not a rectangle then, as Ege says, you need to specify owin(poly=...) using the coordinate locations of the vertices of the polygon.
Don't you have information about the plot? E.g. the coordinates of the corners of a polygonal region delimiting the plot? If you have these coordinates use them as input in the argument poly of owin. See the help file for owin for details. In lack of any information you can try ripras to estimate the boundary of the plot.
What you do right now is to say that you define a point pattern in the rectangle [0,131]×[0,130] and then you provide a bunch of points with coordinates outside this area (much larger coordinate values) and they are all discarded.
I have DNA segment lengths (relative to chromosome arm, 251296 entries), as such:
0.24592963
0.08555043
0.02128725
...
The range goes from 0 to 2, and I would like to make a continuous relative frequency plot. I know that I could bin the values and use a histogram, but I would like to show continuity. Is there a simple strategy? If not, I'll use binning. Thank you!
EDIT:
I have created a binning vector with 40 equally spaced values between 0 and 2 (both included). For simplicity's sake, is there a way to round each of the 251296 entries to the closest value within the binning vector? Thank you!
Given that most of your values are not duplicated and thus don't have an easy way to derive a value for plotting on the y-axis, I'd probably go for a density plot. This will highlight dense segment lengths i.e. where you have lots of segment lengths occurring near each other.
d <- c(0.24592963, 0.08555043, 0.02128725)
plot(density(d), xlab="DNA Segment Length", xlim=c(0,2))
I have a centroid, e.g., A. and I have other 100 points. All of these points are of high-dimensions, e.g, 1000 dimensions. Is there a way to visualize these points in a two-dimensional space in-terms of their distance with A.
A common (though simple) way to visualize high-dimensional points in low dimensional space is to use some form of multi-dimensional scaling:
dat <- matrix(runif(1000*99),99,1000)
#Combine with "special" point
dat <- rbind(rep(0.1,1000),dat)
out <- cmdscale(dist(dat),k = 2)
#Plot everything, highlighting our "special" point
plot(out)
points(out[1,1],out[1,2],col = "red")
You can also check out isoMDS or sammon in the MASS package for other implementations in R.
The distance (by which I assume you mean the norm of the difference vector) is only 1 value, so you can calculate these norms and show them on a 1D plot, but for 2D you'll need a second parameter.