Hi everybody. I have a simple question for bioinformatics. I´d like make a scatterplot of 2 of my columns from a table .csv or .tabular. How can I do that? Thanks!
Unconfigured Ad
Collapse
X
-
Code:library(data.table) # Read data with fread. # You could also use read.table or read.csv, but fread has many advantages. data <- data.table::fread("test.csv") # Basic scatter plot. plot(data$V1, data$V2) library(ggplot2) # A slightly different scatter plot with ggplot2 # Very easy to generate prettier plots with ggplot2. # Takes time to understand underlying concepts though. ggplot2::qplot(data$V1, data$V2)
Comment
-
-
@dpryan
That's fine.
Your answer does raise a good point for a novice R user.
@Marcos Lancia If your csv file does have column headers, you should use those instead of V1 and V2, which are the default column headers generated by fread.
There are several other subtleties, even for this question, which is just about the most basic question one can ask in R.
That's why I've stopped trying to teach R to wet-lab biologists.
I like fread, because it is extremely fast, and can detect several other features of the files, such as the column separator, or the presence or absence of column headers, which often have to be explicitly specified with read.csv.
However, fread returns a data.table by default, not a data.frame, which is a slightly different data structure.
If you'd like to get a more traditional data.frame, you just have to specify data.table = FALSE.
With a data.table, you can't specify the column index in exactly the format given by @dpryan. You can specify the column by the column label in the same manner, though.Code:fread("test.csv", data.table=FALSE)
To get the first column by index of a data.table, you need to use the following format.
Hopefully, you're not now completely lost.Code:data[, 1, with=FALSE]
You'll understand why I've stopped given workshops in R. D)
@dpryan's answer is more direct. read.csv() and plot()
Comment
-
-
Yes, that's not going to work.
You can't have space in a R variable name.
As always, there is a work-around.
You can put the variable names in back ticks: `FC transcriptome`is acceptable.
You need to call log2 on the column too.
log2(d$`FC transcriptome`)
The function read.csv must have replaced the blank spaces by periods anyway.
So, the correct code would be.
You should check the head of the data frame, to be sure that you have the correct column names, and that the file was read correctly.Code:plot(log2(d$FC.transcriptome), log2(d$FC.translatome))
EDIT for updateCode:head(d) colnames(d)
If the colunm name in your file is log2(FC transcriptome), read.csv will convert the column name to log2.FC.transcriptome.
Just check the colnames and the header of the data frame with the commands posted above.Last edited by blancha; 10-16-2015, 06:27 AM.
Comment
-
-
Just want to point out that with RStudio you can import a file by just clicking on "Import Dataset", and also just view the data frame by clicking on the name of the data frame.
Highly recommend RStudio for both novices and power users.
Edit for update
Just post the output of the following command, so that we know the format of your data frame.
Code:head(d)
Comment
-
-
I tried before with plot(d[,10], d[,24]), but it says "error in evaluating the argument 'x' in selecting a method for function 'plot': Error in `[.data.frame`(d, , 10) : undefined columns selected"
> head(d)
test_id.gene_id.gene.locus.sample_1.sample_2.status.value_1.value_2.log2.FC.transcriptome..test_stat.p_value.q_value.significant.test_id.gene_id.gene.locus.sample_1.sample_2.status.value_1.value_2.log2.FC.translatome..test_stat.p_value.q_value.significant
1 TCONS_00000001\tXLOC_000001\tMedtr1g004940\tchr1:688-7366\tSN16 mock\tSN16 Sm\tNOTEST\t0\t0\t0\t0\t1\t1\tno\tTCONS_00000001\tXLOC_000001\tMedtr1g004940\tchr1:688-7366\tTRAP mock\tTRAP Sm\tNOTEST\t0\t0\t0\t0\t1\t1\tno
2 TCONS_00000002\tXLOC_000002\tMedtr1g004950\tchr1:14513-15729\tSN16 mock\tSN16 Sm\tNOTEST\t0\t0\t0\t0\t1\t1\tno\tTCONS_00000002\tXLOC_000002\tMedtr1g004950\tchr1:14513-15729\tTRAP mock\tTRAP Sm\tNOTEST\t0\t0\t0\t0\t1\t1\tno
3 TCONS_00000003\tXLOC_000003\tMedtr1g004960\tchr1:16282-18382\tSN16 mock\tSN16 Sm\tNOTEST\t0\t0\t0\t0\t1\t1\tno\tTCONS_00000003\tXLOC_000003\tMedtr1g004960\tchr1:16282-18382\tTRAP mock\tTRAP Sm\tNOTEST\t0\t0\t0\t0\t1\t1\tno
4 TCONS_00000004\tXLOC_000004\tMedtr1g004980\tchr1:31972-32344\tSN16 mock\tSN16 Sm\tNOTEST\t0\t0\t0\t0\t1\t1\tno\tTCONS_00000004\tXLOC_000004\tMedtr1g004980\tchr1:31972-32344\tTRAP mock\tTRAP Sm\tNOTEST\t0\t0\t0\t0\t1\t1\tno
5 TCONS_00000005\tXLOC_000005\tMedtr1g004990\tchr1:35909-40554\tSN16 mock\tSN16 Sm\tNOTEST\t0
6 203657\t0
Comment
-
-
The default line separator for read.csv is the comma.
If your file is tab-delimited, it will not separate the columns by tab.
Choice #1: Use read.csv, and specify the separator. Not my favorite solution, but most commonly used.
Choice #2: Much better in my opinion. Install dtable, and use the fread function.Code:d <- read.csv("test.csv", sep="\t")
fread automatically picks up the column separator
Choice #3Code:install.packages("data.table") library(data.table) d <- fread("test.csv", data.table=FALSE)
Use the Import Dataset button in RStudio.
Specify the column separator in pop-up menu.
Quick solution for R novices.
Comment
-
Latest Articles
Collapse
-
by mylaserKheloyar – Everything You Need to Know About Kheloyaar Login and Kheoyar Id
If you are looking for an online gaming platform that offers a user-friendly experience, Kheloyar has become a name that many users search for. Whether you're interested in creating a new account, accessing your dashboard through Kheloyaar Login, or learning how to obtain a Kheoyar Id, understanding the platform's features and account process is essential.
This guide explains everything you need to know about...-
Channel: Articles
Yesterday, 01:13 AM -
-
by SEQadmin2
Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
...-
Channel: Articles
07-09-2026, 11:10 AM -
-
by SEQadmin2
Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.
There is no single reason why many patients don’t respond to treatment as expected. Cancer is...-
Channel: Articles
07-08-2026, 05:17 AM -
ad_right_rmr
Collapse
News
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by SEQadmin2, 07-09-2026, 10:04 AM
|
0 responses
20 views
0 reactions
|
Last Post
by SEQadmin2
07-09-2026, 10:04 AM
|
||
|
Started by SEQadmin2, 07-08-2026, 10:08 AM
|
0 responses
12 views
0 reactions
|
Last Post
by SEQadmin2
07-08-2026, 10:08 AM
|
||
|
Started by SEQadmin2, 07-07-2026, 11:05 AM
|
0 responses
30 views
0 reactions
|
Last Post
by SEQadmin2
07-07-2026, 11:05 AM
|
||
|
Started by SEQadmin2, 07-02-2026, 11:08 AM
|
0 responses
31 views
0 reactions
|
Last Post
by SEQadmin2
07-02-2026, 11:08 AM
|
Comment