Creating a Polygon in r -- without connected vertices [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 7 years ago.
Improve this question
I am trying to create a polygon out of this line graph -- is it possible to do without having connected vertices? If so, how do I change the polygon code to do so?

I'm assuming the reason you what to create a polygon is to shade or color within its boundaries. If I'm wrong about that assumption then you really should put more effort into making your questions explicit. The trick is to connect at the ends of those lines by putting them both in one vectors, at the same time as reversing the X and Y for one of the series.
x <- 1:100
y1=6 + rnorm(100)
y2 = rnorm(100)
plot(x, y1, ylim=c(-3,10) )
?polygon
polygon(x= c( x, rev(x) ), y=c(y1,rev(y2) ), col="red")

Related

Hist of circular residual in R programme between -pi and pi [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 3 years ago.
Improve this question
I have the data of error, firstly I need to transform the range of data between -pi and pi
then using code hist(error)
my question is how I can transform this data using code in R, if there exists code please tell me?
error<- c( 5.71444784 ,5.55435896 ,5.60671884, 5.19927462 ,4.81470000 ,5.53028500,
0.87085808 ,5.37982604, 5.43760222 ,5.77523327, 5.68796681 ,5.54533123,
5.27149485 ,5.75717780 ,0.53623627 ,5.29496664 ,5.33288247 ,5.49297135,
5.51343389 ,4.87307837 ,4.87849468 ,5.78305665, 0.13721761 ,5.91185037,
5.50741540 ,5.72588264, 5.03918574, 4.14846564 ,5.25644862 ,0.57956841,
0.37614739, 0.40864692, 5.92087811, 5.92689660, 5.72889189 ,5.64643955,
5.96902437, 5.91666449, 6.18508456 ,5.86249974 ,5.17279359, 5.37982604,
5.25163450, 5.43098155, 5.73912232, 5.80592625 ,5.43940710, 4.84659734,
5.76078923, 5.76379847, 5.76078923 ,5.78606589, 5.68977169 ,5.68375320,
0.42790509 ,6.08939254, 4.89955940 ,5.53389643, 5.67954126 ,5.71324348,
5.66930915 ,5.54111761 ,5.87273017, 5.86791605 ,5.50199909, 5.50199909,
5.69699455 ,5.29737370 ,4.97117745, 5.62838408 ,5.77402891, 5.30640144,
5.85106494 ,5.58926555 ,5.58926555 ,4.62271379 ,3.36547454, 6.19892642,
0.28888093 ,6.09541103, 5.89499926 ,5.87453672, 5.67954126 ,5.46408326,
1.44982681 ,0.24193736 ,0.77516606 ,5.88055521, 5.55435896, 5.58926555,
5.58926555 ,5.39126084, 4.47466189, 0.06800662, 5.75777998, 5.44963921)
I try this problem by transforming the data handly .... and hist ... but the residual doesn't about zero.
To compute the range from -pi to pi just subtract pi from the radian measurement since radians range from 0 to 2*pi:
error - pi
hist(error - pi)
But that does not give you what you want. You really need to use circular statistics to see what is going on:
install.packages("circular")
library(circular)
plot.circular(error, stack=TRUE)
You can ignore the warning message. Notice that the data are not around zero. To plot a histogram we need to cut the data at pi and flip the values greater than pi:
errortrans <- ifelse(error<pi, error, error-2*pi)
# Alternate transform
# errortrans <- ifelse(error<pi, -error, 2*pi-error)
hist(errortrans, xlim=c(-pi, pi))

Find x and y coordinates where a perpendicular point crosses a straight line [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 3 years ago.
Improve this question
This is a follow-up question to this question.
Taking the following image as an example:
What I know:
x and y coordinates of points D, E, and P.
Therefore, I also know slope and intercept of D-E line
What I want to know:
x and y coordinates of point Q. (This is the point which crosses the D-E line).
Notation P=[px,py], D=[dx,dy], E=[ex,ey], Q=[qx,qy]
First:
R=P-D=[px-dx, py-dy]=[rx,ry]
K=E-D=[ex-dx, ey-dy]=[kx, ky]
Then
z=dot(R,K)/dot(K,K)=(rx*kx+ry*ky) / (kx*kx+ky*ky)
Finally
Q=D+z*K=[dx+z*kx, dy+z*ky]
The R is vector which start on point D and ends on point K, the K is vector which start on point D and ends on point E. Using this we made scalar projection to calculate result Q. More info about concept here

Getting theta of Line Equation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
Please forgive my lack of knowledge, which i think it's one of those basic formula related to Trigonometry.
Let's look at visual example:
I have 5 lines, with their line equation (let's say they have zero offset ok)
how can i calculate the Theta of each line equation make (in Pi)?
also I have seen this:
Are they generated from Theta of line equations? or it's another theory which help to find the theta?
much appreciate your time and effort
For equation
y = k * x
tg(Theta) = k
and
Theta = Arctg(k) //arctangent function
General line equation
A * x + B * y + C = 0
(It is more general than y=ax+b and includes cases of vertical and horizontal lines)
Theta = atan2(A, B)
(function atan2 or ArcTan2 exists in math libraries of many programming languages)

plotting 3d graph by stacking 2d contour plots in R [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I have got two different variables x and y that are both functions of variable z. I have multiple contour plots of x vs y at different z values. What I want to do is put these graph slices together along z axis to get a 3D-ish graph.
I searched for packages that lets me do this in R and all I could find was contourrslice in Matlab. Contourslice is exactly what I want but in R.
Is there a package/ function in R like contourslice or any other ways I could go about doing this?
EDIT: Here's a dummy data. For different values of z the heat map changes. I have these several 2D plots, for values of z from -1 to 15. I want to put these 2D plots together along z axis to get a 3D ish figure to see how the red area is displaced.
#Create range of values for x and y
x<- c(11,25)
y<- c(1,5)
length<-10
x_ran <- as.matrix(seq(x[1],x[2], len=length))
y_ran <- as.matrix(seq(y[1],y[2], len=length))
#initialise matrix
x_mat<- x_ran[,rep(1,length)]
y_mat<- t(y_ran[,rep(1,length)])
#Third variable z
z<- -1
#z<- 1
#z<-2
#z<-3
#R and C, funcition of z
R <- x_mat*z
C<-z-y_mat
toget<- R/C
image(toget, xlab="R", ylab="C")

Logical Venn Diagrams [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I have this question :
Unfortunately, my book didn't provide definition and how to draw/read a logic venn diagram, i have to look at the internet but couldn't find any understandable explanation
From what i understand, the logics for the three diagrams are :
X AND NOT (Y OR Z)
NOT X AND (Y OR Z)
Y AND NOT (X OR Z)
Am i right ? Please correct me if i'm wrong
By the ways, does the question mean to combine all three diagrams with OR operation, like :
1 OR 2 OR 3
Any help is greatly appreciated !
I could not understand the question correctly. Here's the logic for the three Venn Diagrams:
1. Your logic for the first Venn Diagram is correct: X AND NOT (Y OR Z)
2. Your logic for the second Venn Diagram is slightly incorrect, if you look at the Venn Diagram: It is simply NOT (X) (Everything except X).
3. In this case as well, the logic is simply Y.
Now if we perform OR operation on these three:
(X AND NOT (Y OR Z)) + NOT(X) + Y
= X AND NOT(Y) AND NOT(Z) OR NOT(X) OR Y [By de Morgan's law]
which matches option c.
NOTE: Your second and third logics would have been correct if X, Y and Z were the only three regions in the diagram. However there is also a region outside all of them - bounded by the box. You might want to look up on the internet about basics of Venn Diagram, it's one of the easiest things to learn IMO!

Resources