Plotting in R missing indices in x plot [closed] - r

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am drawing a plot in R as follow:
respCSV=read.csv("R1.csv")
respCol=respCSV[["RESP"]]
plot(respCol,type='o')
when it plot the series, the x axis lable are not countinuous, instead of 1,2,3,4,
it is 1,5,10.how to fix that?

If the issue is that the axis labels are too spare, and your x variable is continuous you can make your own. This works on standard calls to plot and sometimes it works on plots based on it, but not always.
plot(x, y, xaxt = 'n') # get rid of the default x-axis
axis(1, at = 1:10, values = 1:10) # put the values you want.
Note that there may be other reasons why your axis labels aren't showing up. If the x-axis isn't continuous, the solution will be different.

Related

How to have a horizontal filling areaplot in R [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
Imagine a normal area plot of a continuous function y = f(x), which fills the area below the plotted graph down to the x-axis.
But I have to plot my data transposed. The y-data is now on the horizontal axis and the x-data is now on the vertical axis. I want to have the very same plot as before, just transposed ... so the filling should go left, towards the vertical y-axis.
But I can't find a fitting argument for this in the R documentation of areaplot
Can you help me? Is there a work around?
You can switch the axes just by switching where you use x and y. You can fill the area "under" the curve using polygon. Here is a simple example with the Gaussian distribution.
## Data
x = seq(-3.5,3.5,0.1)
y = dnorm(y)
## Plot
plot(y, x, type="l", xaxs="i", xlim=c(0,0.45))
polygon(y,x, col="gray")

Function in R which gives custom colour (from a given interval) to the borders of a continuous data plot using ggplot2 [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
The function supposed to use colours from the give scale (between low and high) for the border colours if I plot continuous data plot using ggplot2.
> scale_colour_continuous <- function(...) {
> ggplot2::scale_colour_gradient(..., low = "#FFFF00", high = "#3366FF",
> na.value = "#262626", aesthetics = "colour")
Unfortunately, my code above doesn't appear to be working. I find if very interesting, because the same thing for the the fills of the plot works fine with the same arguments (aesthetics = "fill"). What am I missing here?
You don't need to explicitly call ggplot2. If you want to,you could add an if statement that checks if ggplot2 is loaded. This works as required.
my_theme<-function(...){
scale_colour_gradient(..., low = "#FFFF00", high = "#3366FF",
na.value = "#262626", aesthetics = "colour")
}
library(tidyverse)
iris %>%
ggplot(aes(Sepal.Length,Petal.Length,col=Sepal.Length))+
geom_point()+
my_theme()#wanted to make a theme so don't mind the naming.

How to create boxplot with large amount of continuous x-variables and continuous y-variables with R (not ggplot) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How to create boxplot with large amount of continuous x-variables and continuous y-variableswith R
don't use ggplot.
Just like the following figure, the x-axis and y-axis are all continuous numerical variable.
example boxplot
You can plot by boxplot() function. From this tutorial :
https://www.r-bloggers.com/box-plot-with-r-tutorial/
r-blogger is good for your start learning R. Good luck.
You have a multiple options:
http://www.statmethods.net/graphs/boxplot.html
https://www.r-bloggers.com/box-plot-with-r-tutorial/
https://stat.ethz.ch/R-manual/R-devel/library/graphics/html/boxplot.html
https://plot.ly/r/box-plots/
Boxplot between two variables
boxplot(xval~yval)
I would advise a scatterplot though
Now suppose I want to reduce the number of boxplots, I would convert the x axis into some mind of bins using cut
cut divides the range of x into intervals and codes the values in x according to which interval they fall
newyval=cut(yval,20) for 20 bins
then
boxplot(xval~newyval)

ggpairs displaying density functions as unfilled lines [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am hoping to just change the diagonal plots to have simple outlines so I can view the overlap of the density functions more clearly but am not having much luck. Here is the code I have been using:
plot_rh <- ggpairs(data_rh[,1:6], mapping = ggplot2::aes(color = Condition_name),
lower = list(combo = wrap(ggally_facethist, bins = 10)),
diag = list(continuous = wrap("densityDiag"), mapping = ggplot2::aes(fill=Condition_name)))
Plot with filled density functions:
Changing aes(fill=Condition_name) to aes(color=Condition_name) should result in unfilled lines.
You could also change it to aes(fill=Condition_name), alpha = 0.4 to make the filled densities semi-transparent which may improve the view.

R - what is the best way to plot multiple functions $y=cx$ where c is a parameter [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to plot the function y=cx depending on c. It is going to be number of lines going through the point (0,0).
What is the best way to do it?
I mean something like this:
Using abline function seems to be the way. Thanks for the help.
Think this should work. Not sure if it's the best way though
plot(x = 0,y = 0,xlab = "X",ylab = "Y", xlim = c(-10,10), ylim = c(-10,10))
c <- c(1:10) #Store the different values of your constant in this vector
for(i in 1:10){
abline(coef = c(0,c[i]))
}
If you want different limits on your X and Y axis change the values of xlim and ylim.

Resources