Before college, I didn't have access to computers. When I was a freshman in C, a lot of times a program would appear like the following:
At first I thought the computer was overheating and I had to turn it off and let it rest.
When it comes to programming, many biomedical researchers say they have a headache and don't want to touch anything programming related.
I think a lot of the reason is that I have learned the C language for most of the semester, and still stay in the black raw output input interface without a sense of achievement.
This article describes how to draw basic shapes with R.
1.First we install R and Rstudio, R, must be installed Rstudio not must, but can help us better to write programs.
2.Draw histogram
x = c("con","exp1","exp2","exp3")
y = c(5,8,9,7)
png(file = "E:/barchart.png")
barplot(y,names.arg =x)
dev.off()
The above code, the x and y can be interpreted as Numbers, x is con on behalf of the control group, in exp1-3 on behalf of the three group, y is the corresponding number, then output the PNG to E disk, named barchart. PNG, and then use the map function barplot (), finally closed and the output image.
So we got barchart.png in the E disk, as follows:
There are a lot of parameters in the barchart () function to adjust the font, color, location, size, and so on.
3.Drawing line drawing
y = c(5,8,9,7,10)
png(file = "E:/line_chart.png")
plot(y,type="o")
dev.off()
The above parameters do not need to be explained too much, and the function used is the plot () function. After the operation, the following images are shown in the E disk:
4.scatterplot
x = c(1,2,3,4,5,6,7,8,9,10,11)
y = c(5,8,9,7,10,6,4,7,8,3,9)
png(file = "E:/plot.png")
plot(x,y)
dev.off()
The scatter plot requires X and Y values, and the above function is still the plot () function, which is run and then gets the following image.
Of course you can change the type of the scatter point, you can have more than 20 types of triangles, squares, etc., and you can even customize the scatter type.
5.Draw the pie chart
x = c(5,8,9,7)
label = c("January", "February", "March", "April")
png(file = "E:/pie.png")
pie(x,label)
dev.off()
There needs to be a label label in the pie chart, and the above image is obtained as follows:
6.boxplot
png(file = "E:/boxplot.png")
boxplot(mpg ~ cyl, data = mtcars, xlab = "Number of cylinders",ylab = "Miles per gallon")
dev.off()
The above function is a little more complicated, and in this little introduction, it works:
Let's take a look at the entire programming interface:
Looks like the picture above is very ugly, in fact, just we don't have to add more parameters, a slight increase some parameters or use had written a good package, you can draw the following pictures:
Or:
R language is not only the simple drawing of the user mentioned above, but also the more powerful function in statistics and bioinformatics data analysis, have time to learn!
prev:These animals have "conquered" cancer, and humans are learning from them(2017-07-26)
next:How to understand antibody application(2017-07-27)