I am plotting data from an encoder with scilab.In order to use the plotted data i must extract it.I have been look with nothing usefull.
Is there a known way for data extraction in scilab?
After looking at how the process is done in Matlab ,i could found out a certain analogy:
Here is the code to extract data from scilab .You have first to select the plot as a current plot in the plot window:
e2=gca()//extract the current plot handler
b2=e2.children//i don t know what is this is really
b2.data(:,2)// data is a matrix containing X and Y ,in my case i want to extract Y
The following works for me:
Just select the plot as current and get the handle of it from the command prompt:
h = gca();
And then retrieve polygon handle:
p = h.children;
Finally get the graph handle like the following:
c = p.children;
Print the plot data:
c.data
Related
I have a small dataset with EU member states that contains values on their degree of negotiation success and the activity level the member states showed in the negotiations.
I am doing a linear regression with R.
In short the hypothesis is:
The more activity a member state shows, the more success it will have in negotiations.
I played around a lot with the data, transformed it etc.
What I have done so far:
# Stored the dataset from a csv file in object linData
linData = read.csv(file.choose(), sep = ";", encoding = "de_DE.UTF-8")
# As I like to switch variables and test different models, I send the relevant ones to objects x and y.
# So it is easier for me to change it in the future.
x = linData$ALL_Non_Paper_Art.Ann.Recit.Nennung
y = linData$Success_high
# I put the label for each observation in a factor lab
lab = linData$MS_short
# After this I run the linear model
linModel = lm(y~x, data = linData)
summary(linModel)
# I create a simple scatterplot. Here the labels from the factor lab work fine
plot(x, y)
text(x, y, labels=lab, cex= 0.5, pos = 4)
So far so good. Now I want to check for model quality. For visual insepection I found out I can use the command
plot(linModel)
This produces 4 plots in a row:
Residuals vs Fitted
Normal Q-Q
Scale Location
Residuals vs Leverage
As you can see in every picture R marks problematic observations by a number. It would be very convenient if R could just use the column "MS_short" from te dataset and add the label to the marked observations. I am sure this is possible... but how?
I work with R for 2 months now. I found some stuff here and via googe but nothing helped me to solve the problem. I have no one I can ask. This is my 1st post here an stackoverflow.
Thank you in advance
Rainer
With the help of G. Grothendieck I solved the problem.
After entering the R-help of plot, more specific the help for plot and linear regression (plot.lm) with the command
?plot.lm
I read the box with the "arguments and usage" part and identified the labels.id argument AND the id.n argument.
id.n is "number of points to be labelled in each plot, starting with the most extreme."
I needed that. I was interested in the identification of this extreme points. R already marked the 3 most extreme points in all graphics (see initial post) but used the observations numbers and not any useful labels. Any other labelling would mess up the graphics. So, we remember: In my case I want the 3 most extreme values to be labelled.
Now let's add this to the command:
I started the same as above, with a plot of my already computed linear model -> plot(linModel). After that I added "id.n =" and set the value to "3". That looked like that:
plot(linModel, id.n = 3,
So far so good, now R knows what to label BUT still not what should be used as label.
For this we have to add the labels.id to the command.
labels.id is the "vector of labels, from which the labels for extreme points will be chosen."
I assumed that one column in my dataset (NOT the linear model!) has the property of a vector and so I added a comma and then "labels.id =" to the command and typed in the name of my dataset and then the column, so in my case: "linData$MS_short" where linData is the dataset and MS_short the column with the 2 letter string for each member state. The final command looked like this:
plot(linModel, id.n = 3, labels.id = linData$MS_short)
And then it worked (see here). End of story.
Hope this can help some other newbies. Greetings.
I am writing some plotting functions for a large time series database (extract of the data). I wrote a code to plot all the parameters (columns) against the time (first column of the data frame) linked to a given cycle (data frame). I am using a loop to plot all the parameters at once. The problem is that when I call the function, that uses the package ggplot2, only 20 plots out of the needed 34 appear in different windows. I obtain all plots between plot of parameter 11 (Gas_Flow_Mon_01) and plot of the last parameter 34 (Timer_24_Resettable_Value). I don't know if the problem lies within my code or if 20 is the full capacity of windows displayed at once using ggplot2? I have heard of functions like dev.off() but don't know if they would help in dealing with this issue.
# Function plotting all the parameters for one cycle using the indexes of the parameters and the cycle :
# `plot_cycle_allparameters_interactive()`
library(plotly)
library(tidyr)
plot_cycle_allparameters_interactive <- function(datafile,Cycle_index){
Cycle_name = names(datafile)[Cycle_index]
Cycle_data = datafile[[Cycle_name]]
# Cycle_data is the datafile studied that consists of multiple columns, each one representing a parameter
for(i in 2:length(Cycle_data)){
# looping through all the columns that represent a parameter
figure_interactive <- ggplot(Cycle_data, aes(x =Time,y = Cycle_data[,i], group= 1)) +
geom_line(color='blue')
print(ggplotly(figure_interactive))
dev.off()
}
}
I have done the clustering using Rattle and at the end I have the following format of data:
I need to draw the boxplot for each cluster in the same diagram. (i.e there are 5 clusters. So, in X axis, I need 1 to 5 cluster numbers and in Y axis I need age.)
I did the following things. But I couldn't get as I expect.
Can anybody suggest correct settings to get 5 box plots in parallel for each cluster?
In R u can make it. first read the file in frame.
reviews <- read.csv ("abc.csv", stringsAsFactors=FALSE)
boxplot(reviews$age ~ reviews$Cluster)
I'm trying to look at the path of an MCMC trace and the following plain plot() shows the sort of thing I am after, however, when I try the same in ggplot2, it unhelpfully sorts the x-axis values - which I might like in some circumstances, but not now.
set.seed(123)
t1 <- data.frame(x=rnorm(20), y=rnorm(20))
plot(t1$x, t1$y, type='b')
qplot(t1$x, t1$y, geom=c('point','line'))
How do I get something like in the plot() in ggplot2?
Use path instead of line. line will connect points from smallest to largest x value but path will connect them in order as they are in data frame.
qplot(t1$x, t1$y, geom=c('point','path'))
I'd like to plot a bar graph showing frequency of a string in ggplot. The input file (t1. txt) looks like:
do 4
re 2
mi 5
and my current r script is:
library("ggplot2")
t1<-read.table("t1.txt",header=FALSE,sep='\t')
ggplot(t1,aes(V1))+geom_bar()
However this isn't what I'd like - it has a correct x axis, but the y axis should show the variable from the second column (V2). Can anyone help? Thanks.
All you need to do is put the actual V2 in the command then. The default first two items to aes are x and y. You've only given x.
ggplot(t1,aes(V1,V2))+geom_bar()