I have a continuous stream of data in two columns that I am trying to plot. The data contains different trajectories however, and I want gnuplot to plot theses with lines but not connect the different trajectories. How would I signal gnuplot to recognize these different trajectories and not connect them?
Eg:
1 1
2 4
3 9
new traj
1 1
2 .5
3 .333
Sorry if this has been posted before, I searched for about an hour and gave up. Thanks in advance.
Related
I have a data file with the following format :
y1 y2 y3 y4 ...
1.3 1.1 0.5 0.5 ...
0.2 0.4 0.6 0.1 ...
I know how to use Gnuplot to plot the data in this file. Suppose I have 50 columns, then I use:
plot for [col=0:150] filename using 0:col with lines ...
Now, I want to make a scatter instead of a line plot with points having variable size. I have a different file storing the pointsize variables. I know I need to also use a for loop and:
w p ps variable
However, since the point-size variables are stored in a different file, I do not know how to write the using specification. Normally one uses
using 0:1:2
where the point size variables are stored in the second column etc. But what if these variables are stored in a different file ?
I think I can solve this problem by combining both the data and the pointsize variables file into a single file, but I wonder if one can do this using gnuplot.
Thanks
If there is a one-to-one matchup of lines in the two files, then yes. Assuming file.dat is formatted like the one you show above, and ps.dat contains one header record and then in column 1 the point size for all points in that same line of the data file:
# read point sizes into a data block in gnuplot
set datafile columnheaders
set table $pointsize
plot "ps.dat" using 1 with table
unset table
# Now plot the data, using the value of $pointsize[j+1] for row j of points
# There are two tricky bits here
# 1) the line numbers are counted starting with 0
# but array and datablock entries are counted starting from 1.
# 2) $pointsize is an array of strings. We need to convert this to a
# real number in order to use it as a point size
plot for [i=1:*] "file.dat" using 0:i:(real($pointsize[$0+1])) with points ps variable
file.dat
y1 y2 y3 y4
1 2 4 3
2 3 5 4
3 4 6 5
4 5 8 6
ps.dat
ps
1
5
2
3
I am Beginner in R and I want to create network plot in one column based on another column.
Here an example of what my data frame looks like:
## project-ID ## ## Area-ID ##
1 2
1 3
1 5
2 4
2 2
2 3
so the network plot will show the relation between AreaID ,I didn't found any idea that will help me
I hope someone can help. Thank you!
For future posts, please review how to ask questions here on SO. Generally you are more likely to receive help if you show (1) a decent amount of research effort, and (2) a code attempt.
That aside, the following should get you started.
We can convert the data.frame to an igraph object, and plot the graph.
# Sample data
df <- read.table(text =
"project-ID Area-ID
1 2
1 3
1 5
2 4
2 2
2 3", header = T)
# Convert data.frame to igraph and plot
library(igraph);
ig <- graph_from_data_frame(df);
plot(ig);
Many resources involving plotting and analysing networks/graphs using igraph can be found online, e.g. here, here, here, ...
I am a newbie in R. I need to generate some graphs. I imported an excel file and need to create a histogram on one column. My importing code is-
file=read.xlsx('femalecommentcount.xlsx',1,header=FALSE)
col=file[2]
col looks like this (part) -
36961 1
36962 1
36963 7
36964 1
36965 2
36966 1
36967 1
36968 4
36969 1
36970 6
36971 3
36972 1
36973 6
36974 6
36975 2
36976 2
36977 8
36978 2
36979 1
36980 1
36981 1
the first column is the row number. I'm not sure how to remove this. The second column is my data that I want a histogram on. hist() function requires a vector, I'm not sure how exactly to convert.
If I just simple call -
hist(col)
it gives-
Error in hist.default(col) : 'x' must be numeric
I have tried few commands randomly from the internet, but they didn't work.
My eventual goal is to just generate a good histogram (and maybe other charts) on that column, to get a good understadning of the spread of my data.
It should be col=file[[2]] or col=file[, 2] --- solution given in comment
data import should be in correct way to avoid numeric issue
I am trying to create a line plot in R. For each 'RuleID' in my data frame I want to plot the 'ErrorCount' at each 'ProcessorTimeStamp'
DQ_Counts= data.frame(RuleID=c(1,2,1,2),
ProcessorTimeStamp=as.Date(c('2016-08-04','2016-08-04','2016-08-08','2016-08-08')),
ErrorCount=c(6,8,3,4))
# RuleID ProcessorTimeStamp ErrorCount
# 1 1 2016-08-04 6
# 2 2 2016-08-04 8
# 3 1 2016-08-08 3
# 4 2 2016-08-08 4
This is a plot I found online that I would like the end result to look like all though I am obviously not talking about trees. The code for this plot is here Code for Tree Growth Plot but I don't understand it well enough to make it work for me.
For my plot 'ProcessTimeStamp' would be my x and 'ErrorCount' would by my y. Each line would represent a different 'RuleID'.
One thing to note is that I have 'ErrorCounts' ranging from 0 to over 3 million (this is why I need to report on them to get them fixed!).
Thanks in advance.
This is probably the easiest way to get a basic plot like the one above with your data
lattice::xyplot(ErrorCount~ProcessorTimeStamp, DQ_Counts,
groups=RuleID, auto.key=T, type="l")
Which returns
or you could use ggplot2
library(ggplot2)
ggplot(DQ_Counts, aes(ProcessorTimeStamp, ErrorCount, color=factor(RuleID))) + geom_line()
to get
Could you please help me to solve this problem:
I have a database like below:
Animal Milk Age
1 11.96703591 1
1 13.41236333 2
1 14.85769075 3
1 16.30301817 4
2 17.74834559 1
2 19.08465881 2
2 20.42097204 3
2 14.66094662 4
2 14.70197368 5
3 14.74300075 1
3 14.78402781 2
3 14.82505488 3
3 14.86608194 4
3 14.90710901 5
I want to make a plot between milk versus age, so I use function plot(Milk~Age, data=mydata)
My question is how can I make the same plot (Milk~Age) for each individual, by using only one function. Since I have about 200 animals and if I have to run 200 times to produce 200 curves.
Thanks
Phuong
One approach would be to use library ggplot2 and then make individual facets for each animal. As you have many animals you can change ncol= or nrow= in facet_wrap() to get better view.
library(ggplot2)
ggplot(df,aes(x=Age,y=Milk))+geom_point()+facet_wrap(~Animal)
The following code should create as many plot as you have unique Animal values, and store them in different pdf files in the working directory :
invisible(by(df, df$Animal, function(tmpdf) {
pdf(paste0("plot",tmpdf$Animal[1],".pdf"))
plot(Milk~Age, data=tmpdf, main=tmpdf$Animal[1])
dev.off()
}))
I would say to use ggplot from the ggplot2 package
ggplot(df,aes(x=Age,y=Milk, color=Animal))+geom_point()
edit1: actually this would lose clarity with 200 animals. Did you want all this data point in one graph or spread out across 200 graphs? If the latter then I agree with Didzis