I have been searching for this quite a while, but cannot find an answer to my problem or a minimum example. I would like to make a 3D-plot of a matrix.
An extract of my data looks like this. There are the years, which I would like to use as X-Axis. There is Y, which I would like to use as Y and I would like to plot z.
Year y z
2000 1 467
2000 2 10678
2000 2 25
...
How can I make this a surface plot?
Best
Have you tried searching for how to plot a surface plot in R? It turns out there's at least a persp function, a package called plot3D, wireframe in lattice and plotly.
For starters, try (from the plot3D package vignette)
library(plot3D)
example(persp3D)
example(surf3D)
example(slice3D)
example(scatter3D)
example(segments3D)
example(image2D)
example(image3D)
example(contour3D)
example(colkey)
example(jet.col)
example(perspbox)
example(mesh)
example(trans3D)
example(plot.plist)
example(ImageOcean)
example(Oxsat)
Related
I am looking for a way to plot a wind 3D direction in R or MATLAB.
There are 3 given vector components:
u : x-axis (horizontal)
v : y-axis (horizontal)
w : z-axis (vertical)
For plotting wind directions in 2D, there is the traditional way of using a rose plot like this: https://commons.wikimedia.org/wiki/File:Wind_rose_plot.jpg
Do you have any idea, how I can plot this in 3D using the R statistic engine or MATLAB, by using the additional w vector?
Thanks a lot!
In MATLAB quiver3 will be the most relevant to your case. More information and examples here.
In R package,
is there any way to smoothen the polygon in a polar.plot?
I tried to use the splines, but could not find a way to insert the curved line in the polar.plot..
(I am a begginer in R programming)
I know that mathematically with polar plotting you can get smoothed polygons. An example here is for the square if you plot: 1 + Sin[4*x]/20 from 0 to 2 $\pi$ you will get a smoothed square. Change 4 to 5 and adjust the other constants by interpolation and you may find yourself happy.
I cannot find a straightforward way to make a nice image plot in R, but in polar coordinates. I'm basically attempting to find a R equivalent for the 'polarplot3d' function in MATLAB. I've been playing around with ggplot2 package but without much luck. Am I missing a package that contains functionality for what I'm attempting? thanks in advance for any pointers.
Ok, I'm trying to be more clear about what I'm trying to do. Lets say I want to define a polar coordinate grid, increments in the radial direction are 50m and 2.5 degrees in theta. This should look like a dartboard.
My data (r and angle in below code) are correspond to a radial distance measure and an angle. My desired z-value is the counts of a bivariate histogram between r and angle within the increments described above defining the grid.
My data is like the following:
# synthetic data for angle and distance #
angle <- rnorm(500,mean=90,sd=15)
r <- rnorm(500,mean=700,sd=200)
# bivariate histogram #
observations <- table(cut(angle,breaks=c(seq(0,360,by=2.5))),cut(r,breaks=c(seq(0,1400,by=50))))
# the 'z' data are in observations for each bin of bivariate histogram #
# hot to plot a polar coord image? #
It's very slow to render on my system, but
library(reshape2)
library(ggplot2)
mm <- melt(counts)
ggplot(mm,aes(Var1,Var2,fill=value))+geom_tile()+coord_polar()
ggsave("polar1.png")
appears to work.
I think the following could work. Use mapproject() from the maproj library to transform my xy coordinates acording to a polar projection (or another), Then use as.image() (from fields package) function to build a image object from my new coordiantes and my Z values. Eventually use image.plot().
library("mapproj")
xyProj <- mapproject(x, y, projection="conic", parameters=-90)
library("fields")
im <- as.image(z, x=xyProj)
image.plot(im)
I have a dataset with a x-y-z structure.
X = age of arrival in the city
Y = year of arrival
Z = number of current survivors from X/Y combination
I have no problem plotting this for any given time using RGL in R. However I would like to introduce a time dimension.
I could of course make 23 plots and paste them together, but I would like to be able to manipulate the viewing on the fly, and treat the whole time series as one plot. I have Z values for 23 years. I also would like to colour my plot with an extra z2 variable, being z_year/z_(year-1). Is this possible within the RGl pakcage with some programming or is there a better package available?
Try creating a video like described on SO..
Alternative is a for-loop with a plot and delaying it -> look at ?Sys.sleep
I am working on data distribution which has following follwing points.
input<-read.table("infile",header=TRUE,sep="\t")
table(input)
0.786333 1 1.04453 1.06159 1.33277 1.53607 2.25893
49 938 1 1 36 16 166
if i plot box plot for it, i get single line for lowest datum, highest datum and median.
boxplot(input)
Is there any way to distribute points by normalization so that can have better boxplot with distinct boundary for lowest datum, highest datum and median?
You clearly have a biomodal distribution, I don't think a boxplot is a useful summary here
A density plot is more useful
plot(density(zz))
You could also consider a violin plot which is a bit of a mix between a kernel density plot and boxplot.
Using the vioplot package
library(vioplot)
violplot(zz)