I have two different text files with a list of numbers which I want to plot. One file contains the x values and the other the y values. I know how to plot them if they were in the same file but I don't know how to go about it for the separate files. How do I go about it? I am using GNUplot by the way.
If it is useful here are two small bits of data from both files:
x values
0
563
1563
2563
3563
4563
5563
corresponding y values
738500.0
683000.0
647000.0
623500.0
607500.0
I guess I have seen such a question already, but I can't find it right now.
Well, Linux (in contrast to Windows) has some built-in tools where you can easily append two files line by line.
If you want to do this in gnuplot only (and hence platform independent), the following would be a suggestion.
Prerequisite is that you have your files already in a datablock. How to get this done see: gnuplot: load datafile 1:1 into datablock.
Code:
### merge files by line
reset session
$Data1 <<EOD
0
563
1563
2563
3563
4563
5563
EOD
$Data2 <<EOD
738500.0
683000.0
647000.0
623500.0
607500.0
EOD
maxRow = |$Data1| <= |$Data2| ? |$Data1| : |$Data2| # find the shorter datablock
set print $Data
do for [i=1:maxRow] {
print $Data1[i][1:strlen($Data1[i])-1]." ".$Data2[i]
}
set print
plot $Data u 1:2 w lp pt 7
### end of code
Result:
Related
I spend hours on how to achieve the old behavior from gnuplot 4.6 in 5.2
But no chance! So I feel inspired enough to ask my question ;-D
First the gnuplot backward compatibility claim!
Data:
1 3 hm
2 5 oh
3 0 nice
4 2 krr
First col is x, second y, and third the label of x.
I like to print all values but not all label on the x axis.
How to print every third label only is my question.
As long as I do not print xtic, all can be done easy.
But with ... problems are starting.
In 4.6 I achieved this by
file using 1:2 notitle ...
'' using 1:((int(column(1))%3)==1?-1.:0/0):xtic(stringcolumn(3)) notitle
Whenever the rest of x-value is one, plot a point out of the yrange, in my case -1 and plot the x label, otherwise produce an invalid value and nothing is plotted.
Works wonderful and is easy to modify. Expect you have hundreds of points. Easy going.
HOW TO DO THIS NOW IN GNUPLOT 5.2???
It plots any label value doesnt matter if a valid coordinate pair exists?
Happy for a solution to this.
Offtopic: I really like the gnuplot program it is a fantastic tool even if you sometimes need to find the trick. But the backward portability ... ups ;)
Assuming I understood your problem correctly, i.e. only show every 3rd xtic with using xtic(), try this:
Code:
### only every 3rd xtic
reset session
$Data <<EOD
1 1.2 one
2 2.2 two
3 3.2 three
4 4.2 four
5 5.2 five
6 6.2 six
7 7.2 seven
8 8.2 eight
9 9.2 nine
EOD
plot $Data u 1:2 w p pt 7, \
'' u 1:(NaN):xtic(int($1)%3==1?strcol(3):"") not
### end of code
Result:
Addition:
For the plot command you could also use
plot $Data u 1:2 w p pt 7, \
'' u 1:(NaN):xtic(3) every 3 not
Then it will also display only every 3rd xtic label, but at the same time only every 3rd xtic mark.
I am trying to read following data in R. I could find a code written for numpy but there was not any for R.
According to the link: "After skipping the first three lines, each following 12 lines contains one row of the total 2D array. It's concatenated integers of three digits each. Reading ASCII in R needs a separator keyword, but I don't have a separator here.Any help would be really appreciated.
April 2008 OMI/MLS Tropo O3 Column (Dobson Units) X 10
Longitudes: 288 bins centered on 179.375W to 179.375E (1.25 degree steps)
Latitudes: 120 bins centered on -59.5S to 59.5N (1.00 degree steps)
166217223211241326285354290338228257199268342304270284206277284257222239296
260308184247224202214256242220241234247297278270237201247186238239284263212
201204206191184186177199218199234242242205240231246269233208210227275242213
246222272320276248166201197200188173209231199198234238231188250228285253247
249256181180233249252211210184212242242179287233269310305315234236228135128
117219226194243273280321323389427283352446431379385319265243288309242222346
289306281288271267274235277306306273250235252264274260300304322305357336297
281286324324316347308296323294256289246239197256279298275340317337289322356
315286280281276206228225211220251255244210208232239280274268237252238226181
209246254242274248252250240262253226223229204204228197200209245263253247260
267313334255264206163165188220261300266266240247224208223213262248169260298
208356315279242223222168245286303325329 lat = -59.5
312293362274234235237227305283172142294249334273287306283264267228238348370
314255273250279264261285254275261254246249282223225206214199241236244254276
224224232214225226205192175195204202183176194231285284274277284264275286265
242253247187264238203212213181184188219214221192227209233185217255254325236
206328342260262279277296265222275339239319292237352279311238273169141268188
222266281238251310281268268326363389305366312251281289443469386293271355354
342301281240278232224246244218213251291257222242233254230300323350348289258
256264309269273251241264273292271275236245250280277292280299335323345348367
352358346323265265254246235235266260258206221218212232255259260258246233233
223240299281223208269260233246261257250238232236238210215210218259279291298
304301291271240244205193221244252287306297278214235176261322276282196239296
339340295266256241263348321274309308267 lat = -58.5
Edited: I manipulated original data. First I have removed the first three lines using "sed '1,3d' -i file.txt" which is not that necessary. Second, I have removed the first blank column to have a consistent 3-integer separator by "sed -i 's/^ *//g' file.txt". Then, According to Andrew Gustar, I have tried read.fwf. Now, it reads data column-wise whereas I want them to be read every three data as an input. BTW, output is only one column.
data=read.fwf(fils[1],skip = 0,widths = 3,
comment.char = "l")
It is part of the output:
head(data)
V1
1 166
2 260
3 201
4 246
5 249
6 117
They have two integers long while it should be 3
I am trying to depict my whole-genome sequence (WGS) data of my parasite, using the circos software.
One of the elements I would like to depict, is the areas of the reference genome for which i do not have sequencing data from my parasite.
I order to do this, I have used Samtools to create an mpileup file, from which I have extracted the positions where the sequence depth = 0. I therefore have a file that looks like this:
$chromosome_name $chromosome_position $depth
chr_1 1 0
chr_1 2 0
chr_1 3 0
chr_2 67 0
chr_2 68 0
chr_2 1099 0
chr_2 1100 0
chr_2 1101 0
this means that there are 3 positions in chromosome 1, with no sequence data (depth = 0): namely positions 1, 2 and 3. For chromosome 2, the positions with no data are positions 67, 68, 1099, 1100 and 1101.
Due to the fact that my files are enormous (up to 3 million lines), and the fact that alot of the unsequenced positions come in intervals, I would like to create an interval file from the above data. Also, circos requires such an interval-file in order to create tiles. I therefore need to create a new file from the above, that looks like this:
$chromosome_name $start_pos $end_pos
chr_1 1 3
chr_2 67 68
chr_2 1099 1101
I have searched a bunch, but I have only found questions pertaining to grouping data by pre-defined intervals (e.g. group purchases occurring over a period of 6 months, patients by age etc).
So if anybody can help me out, I will be extremely happy!
Sidsel
Consider using bedtools. Specifically the bedtools merge sub-command:
http://bedtools.readthedocs.io/en/latest/content/tools/merge.html
From this page, it would seem to do what you want:
bedtools merge combines overlapping or “book-ended” features in an
interval file into a single feature which spans all of the combined
features.
Moreover, you can use the -d option to specify max distance between featured to merge:
-d Maximum distance between features allowed for features to be merged. Default is 0. That is, overlapping and/or book-ended features
are merged.
c <- read.table("sid-110-20130826T164704.csv", sep = ',', fill=TRUE, )
so I use the above code to read about 300 csv files.
and some files look like this
65792,1,round-5,72797,140,yellow,75397,192,red,75497,194,crash
86267,1,round6,92767,130,yellow,94702,168,brake,95457,178,go,95807,185,red,96057,190,brake,97307,200,crash
108092,1,round-7,116157,130,yellow,117907,165,red
120108,1,round-8,130173,130,yellow,130772,142,brake,133173,152,red
137027,1,round-9,147097,130,yellow,148197,152,brake,148597,160,red
As you can see the second is longer than other line (for each row the third element is supposed have round#) and when I do read.table R cuts the line in half, below I copied the first 5 columns from R
9 86267 1 round-6 92767 130
10 95807 185 red 96057 190
11 108092 1 round-7 116157 130
12 120108 1 round-8 130173 130
is there a way to edit that so that the row is one line instead of being split?
You can prime the data.frame width by specifying "col.names" argument along with "fill=TRUE" as in:
c <- read.table("sid-110-20130826T164704.csv", sep = ',', fill=TRUE,
col.names=paste("V", 1:21,sep=""))
That's assuming you know how many columns you have. If you don't know, you might want to make a single pass through the file to find the maximum width.
I just have a little problem concerning gnuplot:
I have a huge data file, containing several blocks of data and i just want to plot the data contained in the first line of each block. Thus, i use the every command:
plot "../path/to/data.dat" u 1:2 every ::1::1
The Problem now is, that i want to use "with lines", but gnuplot doesn't join the plotted data with lines.
There are two solutions I can think of:
The first would be setting the terminal type to "table", and then plotting this new table data file.
The second would be using awk within the plot command, such that I extract via awk the first line of data of each block in the original data file.
But I'm quite sure, there have to be much easier solutions?
Thanks in advance,
Jürgen
I think awk solution is very simple already
plot "<awk -v p=1 'n==p; NF{n++} !NF{n=0}' test.dat" w l, \
"test.dat" every ::1::1
With test.dat:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24