How to plot the data I read from a file in R? - r

Our instructor assigned us with typing a R script. We don't have any study paper or source for the codes that the instructor typed on class so I'm trying to get help from the articles on internet but I still couldn't find a guide for what I need. Please don't get me wrong, I don't request for someone to do my homework I'm just looking for some tips or any guide links that can help me. When I search on google, not all of the results are related to this and they are usually not helping me or too complicated. The assignment is:
Read data from a .txt file. (I researched and learned how to read data but my problem is I don't know which type of data should I type on the text file to make it plottable by average, standart deviation, histogram etc.)
On the first screen, plot the data, plot the average and plot the standart deviation as line
on the second screen, plot a line from corner to corner and sort the values on it
third screen, plot the data as histogram and plot the distribution function on it
4th screen, plot the anomaly and anomaly line = 0, then make the values that are higher than the anomaly line with different pch than the ones that is lower
finally get the png of 4 screens (i found how to do this)
Thanks.

Which type of data?
You should use metric data. For example the height/age of pople.
For example let's assuhe you have a dataframe yourDataframe:
height
160
155
176
153
185
On the first screen, plot the data
You can use R's standard plot function there: lines(yourDataframe$height)
plot the average and plot the standart deviation
There are already function for those things (for example mean(yourDataframe$height)). Just ask Google.
You can add those values to your linechart using points(mean(yourDataframe$height)).
I think after you did this you will be able to solve the rest of your assignment by yourself. R has quite a big community and you will find everything you need by googling. I guess this is how most people learn R.

Related

How to draw the following 3D Matlab plot/graph?

I am working on a data analytics project as part of my result.
I have cleaned and sorted my data as I wanted.
I want to show the data as shown in the figure below.
I have multiple files.
Each file represents a single day and the date in each file is hour and activity (as shown in the picture).
I am working in Matlab, I know how to do the 3D graphs. I also know about the ribbon function in Matlab.
But I can't exactly figure out how to draw the following graph. Any assistance will be highly appreciated. Thank you.
If you still haven't solved the issues, you can use ribbon plot in matlab. Please find the details in the following link.
https://www.mathworks.com/help/matlab/ref/ribbon.html
For example, if X is the vector containing all the data, then you can simply write.
ribbon(X(:,1));

Making a 'flip-book' type animation using density plots from R

I'm new to R, but have worked out how to graph the distribution of my students' grades for a given term using a density plot, and have made some ridgeline plots to show how the distribution evolves throughout the academic year.
I'm thinking it might be fun (and make the graphs easier to interpret) if I could make a kind of flip-book animation that went from one terms grades to the next, relatively quickly, to see how the distribution changes. At its simplest, I could just pop these distribution plots into Powerpoint and just scroll through the pages, but I'm wondering what commands I need to put into R's ggplot command to ensure that the axes/scaling from one chart to the next stays consistent from one chart to the next?
At the moment, I'm just making a simple chart using this command, where HT102 is the data from the 2nd term of Year 10, and A8 is a vector containing all the (numeric) grades. I am then doing the same thing with another set of grades called ht103, and so on...
ggplot(ht102, aes(x = A8)) +
geom_density(alpha=.3)
What would you recommend to keep the scaling consistent, and any thoughts on a better way to animate this than just popping them into powerpoint?

Scatter plots in R. Why am I getting boxes around certain points?

Apologies, this is probably the simplest question. I'm having trouble making a scatterplot in R Studio. I am trying to see if amphipod counts are correlated to oxygen content. Whenever I plot this using:
plot(Amphipod~Oxygen...ml.l.)
I get a graph with boxes around certain points and I have no idea why. Only 5 points and I can't see anything different about those.

R: getting data (instead of plot) back from sm.density.compare

I'm doing a density compare in R using the sm package (sm.density.compare). Is there anyway I can get a mathematical description of the graph or at least a table with number of points rather than a plot back? I would like to plot the resulting graphs in a different application, but need the data to do so.
Thanks a lot for the help,
culicidae

Force starting point of lines()

Perhaps because the question is so basic, the keywords that I can think up for this question all directs me to other things. I am trying to draw a graph with spiky curve lines that connect the medians. The real data is very big, but the starting values are duplicates of (0,0):
DATA<-data.frame(time<-c(sort(rep(c(0,2,4,8,12),4))),
conc<-c(rep(0,4),rnorm(n=4,mean=30),
rnorm(n=4,mean=10),
rnorm(n=4,mean=35),
rnorm(n=4,mean=15)))
# Create blank graph
plot(NULL,NULL,xlab="Time",ylab="Conc",
xlim=c(0,15),ylim=c(0,40),main="Example")
# Add line
require(quantreg)
require(plyr)
require(MatrixModels)
DATA<-plyr::arrange(DATA,time)
fit3<-rqss(DATA$conc~qss(DATA$time,constraint="N"),tau=0.5,data = DATA)
lines(unique(DATA$time)[-1],fit3$coef[1] + fit3$coef[-1],lwd=2)
As you can see, the line does not connect to the starting (0,0) values and instead start at the next lowest level.
I was tempted to cheat, but it does not connect to the lines and I would really prefer to work it out with the rest of the code instead of trying to pass off two lines as one:
# Cheating getaway but does not work well, segments are not connected
segments(x0=0,y0=0,x1=2,y1=30,lwd=2)
Some relevant answers that I found were not appropriate for my situation.
Line in R plot should start at a different timepoint for example suggest modifying the data, which would not help to extend my line and plus my actual data is too big that I would be wary to do this kind of manipulation. I would not want to use plot(x,y,type="l") even though it goes through the (0,0) point, because 1) it looks bad on the huge data, and 2) I would have to overlay another similar line using lines(). I wonder whether it has more to do with rqss and less with lines?
I apologize if this has already been asked before.

Resources