I have a data frame similar to the one created in the example below:
Remove columns with zero values from a dataframe
Is it possible to create a whisker plot connecting these two points in R? I would want the variables on the x-axis and the points on the y-axis.
Related
I am trying to subtract the two corresponding values for each of the scatter plots to get a residual. Each point on the scatter plot below has a corresponding point in the plot above, but simply with a different value. For example, NE at the very left has a value of 0.5 in the top scatter plot and I'd like to subtract from it the value in the bottom plot which is 1. I have been trouble doing this. I couldn't get a level of detail calculation to work, because that aggregates everything, and I simply can't make a table calculation of avg(average scores) - predicted score. The predicted score is really just a trend line fitted on to the top scatter plot. Any help is appreciated.
I have several dataset matrices x, y, andz, where z contains values at the positions x,y showing shifted (overlapping) parts of the same picture. x and y are rectangularly centered around different center positions for each dataset.
How can I combine the data in one plot using pcolor or similar? Note that it should be a rectangular plot in the end, but that not all data points are given due to the shift.
I now solved my own question by using the command hold on, which makes it possible to plot several times into the same figure. You just have to run it in between two plot commands.
I have 25 pairs of (x,y) co-ordinates. Each of these pairs corresponds to a country. I want to plot the 25 points on a scatter graph, and have the country name for each point directly next to the point on the scatter graph. I can't figure out how to do this in MATLAB or Octave (I have both MATLAB and Octave and don't mind which I use, which is why I'm asking about both).
Let's say I put the (x,y) co-ordinates and corresponding country labels in a matrix of 25 rows and 3 columns, with the labels in the first column. Does anyone know the command I can use for the desired graph?
Strings don't play well with matrices, so I'm adjusting your storage format slightly. Here's the test data: a 25x2 matrix of coordinates, and a 25x1 cell array of strings.
p = rand(25,2);
names = repmat({'name'}, 25, 1)
You'll have to play with the offsets slightly, but here's the idea:
scatter(p(:,1), p(:,2))
%# Compute some offsets for the lower-left of the text box, based
%# on overall size of the plot
offset_x = diff(xlim) * .01;
offset_y = diff(ylim) * .01;
text(p(:,1)+offset_x, p(:,2)+offset_y, names)
Im faced with a problem where i need to plot a two dimensional data with different colors and markers.
We are given with 2 array, namely points (n x 2 dimension) and Label (n x 1 dimension). Im not sure about the number of unique values in the Label array but maximum could be 10. I would like to plot the points with different color and markers based on its corresponding Label value.
Can any one help me in this regard
Use gscatter, which does a scatter plot, using a group (Label in your case) to plot in different colours/makers.
GSCATTER(X,Y,G,CLR,SYM,SIZ) specifies the colors, markers, and
size to use. CLR is either a string of color specifications or
a three-column matrix of color specifications. SYM is a string
of marker specifications. Type "help plot" for more information.
For example, if SYM='o+x', the first group will be plotted with a
circle, the second with plus, and the third with x. SIZ is a
marker size to use for all plots. By default, the marker is '.'.
So you can specify colours like 'rgcmykwb' to do red for the first group, green for the second, etc or [] just to have Matlab sort it out.
By default Matlab uses the same marker for each group, so you need to specify what markers you want to be used for each group. If you do '.ox+*sdv^<>ph' you'll just cycle along all the markers that Matlab has.
n=50;
% make nx2 matrix of random points.
points = random('unif',0,1,n,2);
% make nx1 matrix of random labels from {1,2,...,5}
labels=round(random('unif',1,5,n,1));
% plot. Let Matlab sort out the colours and we will specify markers.
gscatter(points(:,1),points(:,2),labels,[],'ox+*sdv^<>ph.')
It looks a bit like this:
If I have
matrix=
0.0494 2.3691
-0.0973 0.8026
-0.3040 -0.0861
-0.0626 2.5688
-0.4144 0.7054
0.0633 -0.0991
-0.8386 -1.2229
1.8929 2.6260
1.7687 2.3963
1.8243 -0.5543
1.9272 -0.3946
-0.0682 1.7404
-0.1180 2.2323
0.4071 -0.1878
0.6406 2.5602
-0.2144 2.0014
0.1091 -0.1874
-0.1102 0.2922
How Would you plot one column in a color and other in a different color, or some of them in one color
scatter(matrix(:,1),matrix(:,2), 'b','+');
scatter does not plot each column separately. It is column 1 vs column 2. So, each point on the scatter plot is made up of both columns. In other words, there is no difference between scatter(x,y) and plot(x,y,'o'). However, scatter has other features, which is why it is available as a different function. If you were just trying to plot each column separately with two colors, you can simply do plot(matrix,'o') and MATLAB should automatically assign blue for the first column and green for the second.
scatter also takes a colormap as an argument. So if you intended to plot half your data (both columns) one color and the rest another, you can try this
nRows=size(matrix,1);
red=repmat([1,0,0],fix(nRows/2),1);%# use fix so that you don't get an error if nRows is not even.
green=repmat([0,1,0],nRows-fix(nRows/2),1);
scatter(matrix(:,1),matrix(:,2),[],[red;green]);