Online tool for picking points on the 2D plane and exporting them to coordinates) - plot

I am looking for a specific online tool. At first it displays empty 2D plot (with gridlines from -10 to 10 for example). You can also choose a color. When I select a color and then click on the plot a new point should be drawn on the plot. I can click multiple times so that multiple points are generated on the plot. Then I can change the color and generate more points on the same plot (but with different color). When I'm done I should be able to export the points to list of coordinates and color: [(0, 1, 'blue'), (1, 1, 'green'), (1, 2, 'green')].
Does anyone know such tool? It's purpose is to simply quickly generate 2D dataset with multiple classes.

I wasn't able to find a tool that would exactly meet all your requirements but I think there is a solution that my fulfill some of them.
You can use plotly (https://plot.ly/create/) to plot visualize the points using scatter plot creator.
As for random points you can generate them randomly as well as assign colors to them using some simple python function, like this:
import pandas as pd
import numpy as np
import random
def make_points(minv,maxv,total):
df = pd.DataFrame(np.random.uniform(low=minv, high=maxv, size=(total,2)), columns=list('XY'))
arr=["blue", "green", "purple", "red"]
arr *= total // len(arr)
random.shuffle(arr)
df['color'] = arr
df.to_csv("points")
return df
make_points(-10,10,100)
This for example will create a dataframe with 100 2d points that can get values from -10, 10, and each is randomly assigned one of 4 colors.
Import the csv in the plotly chart creator and you can then manually edit the values if you like.

Related

R generate points with condition using runifpoint function

I am trying to generate randomly distributed points in a rectangle.
To create 50 random points in a rectangle, I used
i=50
pp<-runifpoint(i, win=owin(c(0,19.5),c(0,3.12))
If I were to add conditions on the coordinates before randomly generating points,
e.g. 0.24 <x<19.26 ,0.24<y<2.64 ,
then generate random points, what code can I imply?
The ultimate goal is to generate points in the rectangle except for the grey shaded area, in the below image
This is a question about the R package spatstat.
The argument win specifies the spatial region in which the points will be generated. In your example you have specified this region to be a rectangle. You just need to replace this rectangle by the region in which you want the points to be generated.
You can construct spatial regions (objects of class owin) in many ways. See help(owin), or help(spatstat) for an overview.
In your example, you could build up the shape by forming the union of several rectangles. For example to make a simple cross shape, I could just write
require(spatstat)
A <- owin(c(-1,1), c(-4, 4))
B <- owin(c(-4,4), c(-1,1))
U <- union.owin(A, B)
plot(U)
Another way would be to specify the corners of the polygon shape and use W <- owin(poly=p) where p = list(x, y) contains the coordinates of the corners, listed in anticlockwise order without repetition. See help(owin).
This is also covered in Section 3.5 of the spatstat book. You can download Chapter 3 for free.

Spatial Probability Density Function Contouring

So i'm trying to create a contour plot based on specific point patterns. I want to make it so when the density of the points goes below a certain threshold it stops that contour and starts another. So I want to incorporate a SPDF in to my project here. This is a snipit of what the code would look like with the points scattered within a boundary. The points also wouldn't necessarily be random, but possibly uniform.
library(spatstat)
rect <- owin(c(0, 10), c(1, 4))
rect <- rpoint(100, win = rect)

Self organising map visualisation result interpretation

Using the R Kohonen package, I have obtained a "codes" plot which shows the codebook vectors.
I would like to ask, shouldn't the codebook vectors of neighbouring nodes be similar? Why are the top 2 nodes on the left so different?
Is there a way to organise it in a meaningful organisation such as this image below? Source from here. Where the countries of high poverty are clustered at the bottom.
library("kohonen")
data("wines")
wines.sc <- scale(wines)
set.seed(7)
wine.som <- som(data = wines.sc, grid = somgrid(5, 4, "hexagonal"))
# types of plots
plot(wine.som, type="codes", main = "Wine data")
Map 1 is the average vector result for each node. The top 2 nodes that you highlighted are very similar.
Map 2 is a kind of similarity index between the nodes.
If you want to obtain such kind of map using the map 1 result you may have to develop your own plotting function with the following parameters:
Pick up the most relevant nodes or the most different ones (manually or automatically). Then, you have to attribute a color to each of these nodes.
Give a color the the neigbours nodes using the average distance between the center of each node from the selected nodes. Shorter distance = close color, higher distance = fading color.
To sum up, that's a lot of work for nearly nothing. Map 1 is better and contains a lot of informations. Map 2 is nice looking...

Coloring vertexes according to their centrality

I am trying to change the color of the vertexes in an igraph generated graph.
To be more specific, I have a 95 nodes graph created from an adjacency matrix and I would like to color them according to their degree/betweenness/eigenvalue centrality/closeness but I'm guessing that after I know how to do it with one, I'll be able to do it with others.
So I've coded the basics of graph generation until now:
dataset <- read.csv("~/Google Drive/Cours M2/Network Economics/Data/Collabs_2013.csv", sep=";")
matrix<-as.matrix(dataset)
adj<-graph.adjacency(matrix)
plot(adj)
btw<-betweenness(adj,directed = FALSE)
I now have a vector of 95 values of betweennesses and I would like to plot a graph with a gradient of colors that follows the betweenness values (e.g. from red for the lowest value to green to the highest). I'm guessing I have to mess with vertex's attributes but I have no idea how to input the vector as a color attribute.
Seems like you already did most of the work. All you have to know is colorRamppalette and setting the vertex.color for the network. Assuming you have to change the colors linearly,
just do
fine = 500 # this will adjust the resolving power.
pal = colorRampPalette(c('red','green'))
#this gives you the colors you want for every point
graphCol = pal(fine)[as.numeric(cut(btw,breaks = fine))]
# now you just need to plot it with those colors
plot(adj, vertex.color=graphCol)
credits to this. I was using a much more inefficient method to assign the colors before answering this.
Just a note:
It can be problematic to define
palette = colorRampPalette(c('blue','green'))
as the 'palette' function, is also used by igraph, and so igraph later produces as error.
See problem Color pallette for vertices in igraph network in R

Colour-coded 3D Plot in R

I am new to R, so can someone please help with this?
I have a data frame with 4 columns: x,y,z and freq. One row in this frame represents one point in 3D space (x,y,z are x-,y- and z- coordinates respectively) and it's frequency. I want to plot these points and make these points coloured such that the color is decided by the frequency. For eg: All points with frequency 0 are blue, between 1 and 5 are red, between 5 and 10 are orange, between 10 and 15 are yellow and so on. Some points can have a frequency of 0 also. But I don't know the range of frequency. Max no of colors to be used is 10. Also, there should be a scale explaining the meaning of colors.
I have been trying to correct the following code and make it work, but it`s just not working:
lev <- levels(factor(t$freq));
n <- as.numeric(lev);
n <- n+1;
plot3d(t$x,t$z,t$z,col=n);
Please help! Thank you.
PS- Please tell the solution using rgl package
PPS - I have been trying to manipulate the col arguement in plot3d function of rgl package, but I am unable to get the desired result.
I would load package rgl and do
plot3d(x,y,z, col=colors)
That means that you should prepare a list of color values that is of the same length as x,y,z lists so that you have a color selected for each x,y,z point.
the other part would be to make the list. I would try
givecolor = function(freq){
if(freq < 1) "red"
else if ....
}
colors = sapply(mydataframe[,"freq"], givecolor)
You just need to build a vector of colors that is the same length as the number of points you are plotting. You then pass this vector as the col argument to the rgl plot3d() function. See this page for a demonstration that uses the iris dataset: http://planspace.org/2013/02/03/pca-3d-visualization-and-clustering-in-r/
First you should select a palette you like and pick the number of colors you want, e.g. palette=rainbow(10). Then use a factor you get from splitting your data 10 ways to set your color from the palette.
See 3d scatterplot in R using rgl plot3d - different size for each data point? for how to effectively split a dataframe by a newly created factor. That question is w.r.t. size, but it also works for color.

Resources