I use the lattice package for almost everything I plot in R and it has a corresponing plot to persp called wireframe. Let data be the way Sven defined it. Wireframe(z x. y, data=data) Or how about this (modification of fig 6.3 in Deepanyan Sarkar's book).
I have data formatted like this in a csv file:
lines with first parameter a is one set of data, and first parameter b represents another set.
My aim is to plot two lines on the same graph, one with points
and the other with points
I am able to import the data directly in MS Excel, but am not sure how to plot them. How can I plot this data?
MoebMoeb
2 Answers
You didn't state what version of Excel you are using. This was done in Excel 2010, but should give you an idea how to do it enough to figure it out in another version.
After you've imported your data, select a cell with no data. Insert a blank chart. Then edit the chart data by choosing
Select Data
from the context menu. You will then add a series choosing A1
as the series name, then select the data row by row while holding Ctrl (this allows multi-select). This will plot the numbers in the order you stated. Do not just select all of the data from B1
to D4
or you will get an error.Then do the same thing for
b
by adding another series. CharlieRBCharlieRB
If you want a 3D scatter plot, you will have to use something like this macro, since 3D Scatter is not a build-in chart type. Or you could try R or some other plotting environment.
beroeberoe
Not the answer you're looking for? Browse other questions tagged microsoft-excelchartscsv or ask your own question.
I have a 3D dataset:
And I want to plot it, but the built-in-functions of R alwyas give the error
increasing 'x' and 'y' values expected
When I searched on the internet, I found that this message happens when combinations of X and Y values are not unique. But here they are unique.
I tried some other libraries and there it works without problems. But I don't like the default style of the plots (the built-in functions should fulfill my expectations).
Why are my datasets not accepted by the built-in functions?
R_UserR_User
5 Answers
If you're working with 'real' data for which the grid intervals and sequence cannot be guaranteed to be increasing or unique (hopefully the
(x,y,z)
combinations are unique at least, even if these triples are duplicated), I would recommend the akima
package for interpolating from an irregular grid to a regular one. Using your definition of
data
:And this should work not only with
image
but similar functions as well.Note that the default grid to which your data is mapped to by
akima::interp
is defined by 40 equal intervals spanning the range of x
and y
values:But of course, this can be overridden by passing arguments
xo
and yo
to akima::interp
.hatmatrixhatmatrix
I use the
lattice
package for almost everything I plot in R and it has a corresponing plot to persp
called wireframe
. Let data
be the way Sven defined it.Or how about this (modification of fig 6.3 in Deepanyan Sarkar's book):
Update: Plotting surfaces with OpenGL
Since this post continues to draw attention I want to add the OpenGL way to make 3-d plots too (as suggested by @tucson below). First we need to reformat the dataset from xyz-tripplets to axis vectors
x
and y
and a matrix z
.This image can be freely rotated and scaled using the mouse, or modified with additional commands, and when you are happy with it you save it using
rgl.snapshot
.BacklinBacklin
Adding to the solutions of others, I'd like to suggest using the
plotly
package for R
, as this has worked well for me.Below, I'm using the reformatted dataset suggested above, from xyz-tripplets to axis vectors x and y and a matrix z:
The rendered surface can be rotated and scaled using the mouse. This works fairly well in RStudio.
You can also try it with the built-in
volcano
dataset from R
:MegatronMegatron
I think the following code is close to what you want
It gives data like this (note that
x
and y
are both increasing)and a graph like
HenryHenry
Not sure why the code above did not work for the library
rgl
, but the following link has a great example with the same library.Run the code in R and you will obtain a beautiful 3d plot that you can turn around in all angles.tucsontucson