How to connect specific attributes over polar coordinates in R? - polar-coordinates

I have highlighted specific activities (feeding,resting and sleeping) from the dataset in my plot. Now I want to connect these highlighted points in sequence over my polar coordinates.
Here's my dataset:
Activity Latitude Longitude
Feeding 21.09542 71.06014
Resting 21.09564 71.06064
Sleeping 21.09619 71.06128
Walking 21.09636 71.06242
Walking 21.09667 71.06564
Resting 21.09483 71.06619
Can you help me out in this?

# Example dataframe
set.seed(1)
mydf=data.frame(Activity=sample(c("Walking","Feeding","Resting","Sleeping"),20,T),Latitude=rnorm(20,21,0.5),Longitude=rnorm(20,71,0.5))
mydf$Order=1:nrow(mydf)
If you want to connect the points in order regardless of the activity, do the following (for clarity, I added the variable mydf$Order to label the points).
# Plot
library(ggplot2)
ggplot(data=mydf)+
geom_point(aes(x=Latitude,y=Longitude,colour=Activity))+
geom_path(aes(x=Latitude,y=Longitude))+
geom_text(aes(x=Latitude,y=Longitude,label=Order))+
coord_polar(theta="y")
If you want to connect points according to activities, consider CMichael's answer.

Ok I am starting from scratch: My original answerwas much too bulky and inflexible.
Just add the following to get Paths for each Activity without filtering.
+ geom_path(aes(colour=ACTIVITY,x=Latitude,y=Longitude))
If you want to plot only selected Activities:
+ geom_path(data=Data[Data$ACTIVITY %in% c("Sleeping","Resting"),],aes(colour=ACTIVITY,x=Latitude,y=Longitude))
The selected Activities are to be listed in the c(...) vector with each name quoted.
UPDATE: OP clarified that he wants to connect any stationary point, this achieved by running the following:
+ geom_path(data=Data[Data$ACTIVITY!="Walking",],colour="red",aes(x=Latitude,y=Longitude))
Note that the colour=ACTIVITY is removed from the aesthetics and we consider all stationary points (!="Walking") to draw the path.
Code combining the two answers:
set.seed(1)
mydf=data.frame(Activity=sample(c("Walking","Walking","Walking","Walking","Walking","Resting","Feeding","Sleeping"),20,T),Latitude=rnorm(20,21,0.5),Longitude=rnorm(20,71,0.5))
mydf$Order=1:nrow(mydf)
# Plot
library(ggplot2)
ggplot(data=mydf)+
geom_point(aes(x=Latitude,y=Longitude,colour=Activity),size=5)+
geom_path(aes(x=Latitude,y=Longitude),size=1.2)+
geom_text(aes(x=Latitude,y=Longitude,label=Order))+
geom_path(data=mydf[mydf$Activity!="Walking",],colour="red",aes(x=Latitude,y=Longitude)) +
coord_polar(theta="y")

Related

Restart the numbering of the reference labels in the appendix body in overleaf

I have created a supplementary section in my journal manuscript using the following script:
\appendix
%%%
\renewcommand{\appendixname}{S}
\renewcommand{\thesection}{S}
\renewcommand\thefigure{\thesection.\arabic{figure}}
\setcounter{figure}{0}
\renewcommand*{\thepage}{S\arabic{page}}
\setcounter{page}{1}
%%%
\begin{center}
\section*{Supplementary Material}
\end{center}
%%%
\subsection{Sub-heading1}
A separate bibliography also has been generated for the appendix using the multibib package as follows:
\usepackage[resetlabels]{multibib}
\newcites{supp}{Supplementary References}
and declaring
%% Loading supplementary bibliography style file
\bibliographystylesupp{unsrt}
% Loading supplementary bibliography database
\bibliographysupp{cas-sc-template-refs.bib}
\end{document}
resulting in a reference section that looks like this:
Supplmentary References
However, the reference labels in the body text does not change:
S.2. Discussion
S.2.1. Subheading2
The role of the structural of squares and the circles is clearly seen in the
interdependence of property on the values of energy and density as
shown in Figures S.4a and S.4b. There is a clear clustering of data
points based on the primary property as viewed against its dependence
on secondary property in Figures S.4c. The high-value compositions
are observed to be all apples and the medium value ones are observed
to be oranges. The values thus predicted placed most of them in the
low– and medium–value range [66].
The reference numbers are still from the main document's bibliography.
I have tried the \DeclareOption{resetlabels}{\continuouslabelsfalse} option in the multibib package documentation given in http://tug.ctan.org/tex-archive/macros/latex/contrib/multibib/multibib.pdf but to no avail.
Is there any way to renumber these reference labels as well?

How to display blocks on PlantUML diagram vertically?

I've got the following sample code (in real I've got hundred/thousands of lines):
#startuml
[326976]<->[7bfe53]
[868224]<->[49e442]
[777408]<->[0de431]
[777408]<->[d8d3ed]
[454080]<->[99b073]
[750848]<->[05624c]
[319104]<->[264b51]
[319104]<->[ad0add]
[035840]<->[76d4fe]
[561280]<->[e7fd29]
[576640]<->[388451]
[674816]<->[bafca1]
[674816]<->[ec9992]
[505344]<->[1069ba]
[173120]<->[4ded8e]
[741888]<->[018d22]
[166464]<->[695028]
[122176]<->[5ed43a]
[122176]<->[72fcb1]
[950848]<->[93c4a2]
#enduml
However the diagram looks like:
With more number of blocks, the image (PNG) gets cut off with the following warnings:
Width too large 11516268
Creating image 4096x129
I'd like to display diagram vertically ideally with minimal code changes, is it possible?
My goal is to see shared connections on the graph when ID on the left shares multiple IDs on the right (and other way round).
I think you are looking for: left to right direction.
#startuml
left to right direction
[326976]<->[7bfe53]
[868224]<->[49e442]
[777408]<->[0de431]
[777408]<->[d8d3ed]
[454080]<->[99b073]
[750848]<->[05624c]
[319104]<->[264b51]
[319104]<->[ad0add]
[035840]<->[76d4fe]
[561280]<->[e7fd29]
[576640]<->[388451]
[674816]<->[bafca1]
[674816]<->[ec9992]
[505344]<->[1069ba]
[173120]<->[4ded8e]
[741888]<->[018d22]
[166464]<->[695028]
[122176]<->[5ed43a]
[122176]<->[72fcb1]
[950848]<->[93c4a2]
#enduml
output with left-to-right-direction
Additionally you might want to add double dashes.
#startuml
left to right direction
[326976]<-->[7bfe53]
[868224]<-->[49e442]
[777408]<-->[0de431]
[777408]<-->[d8d3ed]
[454080]<-->[99b073]
[750848]<-->[05624c]
[319104]<-->[264b51]
[319104]<-->[ad0add]
[035840]<-->[76d4fe]
[561280]<-->[e7fd29]
[576640]<-->[388451]
[674816]<-->[bafca1]
[674816]<-->[ec9992]
[505344]<-->[1069ba]
[173120]<-->[4ded8e]
[741888]<-->[018d22]
[166464]<-->[695028]
[122176]<-->[5ed43a]
[122176]<-->[72fcb1]
[950848]<-->[93c4a2]
#enduml
output with double dashes

Error series vanishes on resizing window

Following plot has a error series Series2 which is not displayed on this chart, but legends says about its existence. This series needs to be displayed with minimum y value as infinity. But, Tee chart doesn't have any provision to specify -Infinity directly. So, we defined a huge negative number instead; which is significantly larger than the y axis to give an appearance of -Infinity to the user. But, if the chart area becomes too small compared to this huge negative number, the series (here series2) vanishes entirely.
Here is the series data used -
Series2 Points:
X-------------------->>Bar-------------------->>Std. Error
1432 --------->> -50.19380462 ----------->> 50.20619538
1797 ---------->> 50.19380462 ----------->> 50.20619538
2164 ---------->> -50.19380462 ----------->> 50.20619538
2529 --------->> -50.19380462 ----------->> 50.20619538
Can anyone please help to resolve this issue?
Thanking you.
The next release of TeeChart for .NET includes support for extended Axis ranges, from Double.MinValue to Double.MaxValue, and goes some way further to handle infinite value issues. That doesn't say for sure that it will resolve the issue you describe here. If you are able to send Steema Support a sample project that shows the issue we can test it with the new release.

JavaFX proximity detection not working

I have been trying to figure out how to get two nodes to sense when they are close to each other and then snap together but can't make it work correctly. Basically, I have an AnchorPane that I am dropping new Nodes onto. The new nodes are also anchor panes with several other components on them. When I drop the Node I save anchor points along the outer edge. Then, when I drag another Node next to it, the sides will light up indicating the other node is in range.
I am attempting to make a node that is being dragged next to another node snap to that node. I cannot seem to get the coordinates to translate correctly between each other and I am just ending up with random placement and edge detection.
Here is my code where I am saving the anchor points for the nodes:
double kromaDeviceWidth = kromaDevice.getBoundsInParent().getWidth();
double kromaDeviceHeight = kromaDevice.getBoundsInParent().getHeight();
//This x,y represents the top left corner of the node
double kromaDeviceX = kromaDevice.localToParent(0.0, 0.0).getX();
double kromaDeviceY = kromaDevice.localToParent(0.0, 0.0).getY();
kromaDevice.setTopAnchorPoint(new double[]{kromaDeviceX + kromaDeviceWidth / 2, kromaDeviceY});
kromaDevice.setRightAnchorPoint(new double[]{kromaDeviceX + kromaDeviceWidth, kromaDeviceY + kromaDeviceHeight / 2});
kromaDevice.setBottomAnchorPoint(new double[]{kromaDeviceX + kromaDeviceWidth / 2, kromaDeviceY + kromaDeviceHeight});
kromaDevice.setLeftAnchorPoint(new double[]{kromaDeviceX, kromaDeviceY + kromaDeviceHeight / 2});
The code is identical for when I initially drop a new node and when I am dragging the node. Then, I compare the two node's anchor positions to tell if they are within range:
if (Math.abs(bottomAnchorX - topAnchorPointX) <= ANCHOR_DISTANCE && Math.abs(bottomAnchorY - topAnchorY) <= ANCHOR_DISTANCE) {
....show correct edge highlight
}
I simplified the above if statement as I am using arrays to store and recall the anchor points.
Here is an image of what I am seeing:
You can see the slight yellow highlight when I drag one node over the other when it is offset. It should detect the other node when it is in the position in the second image. My next issue is trying to get them to snap to the right coordinates.
droppedKromaDevice.setLayoutX(parentKromaDevice.getLayoutX());
droppedKromaDevice.setLayoutY(parentKromaDevice.getLayoutY() - droppedKromaDevice.getBoundsInParent().getHeight());
I tried the above with both getLayoutX() and localToParent(0,0).getX() and they produce the same result. If I place two nodes that are exactly the same size than it actually works but if the are different sizes at all than it places them offset from each other. If I subtract the height from the y it should matter the size.
Please help. I have been trying to get this to work right for 3 days now and have tried everything I can think of.
Update:
I figured out my proximity issue. The layout for the new node was not being set right. I tried doing a Platform.runLater before I saved the anchor points of the new node but that had no impact. I fixed it by setting the anchor points for all of the nodes in the pane when I click on a node to drag it. That saved the anchor points correctly.
This however did not fix my issue of nodes of different sizes not laying out in the pane correctly. Here is a screenshot of two nodes of the same size snapping together correctly and two nodes of different sizes not snapping correctly. This makes no sense as the math should be the same.
Here is the code to set the layout for the dropped node relative to the other node:
droppedKromaDevice.setLayoutX(parentKromaDevice.getLayoutX());
droppedKromaDevice.setLayoutY(parentKromaDevice.getLayoutY() - droppedKromaDevice.getBoundsInParent().getHeight());
I found the solution to my two problems.
First, when I was creating new nodes and dropping them on the panel the bounds were not being evaluated correctly so my anchor points were off. I just changed it so when I click on a node to drag it around I loop through all of the other nodes on the panel and build their anchors instead of when I first drop/create it.
Second, in order to get the snap positioning to work accurately I had to base their layout on the delta between the opposite anchor points and not on the bounds of the node. Basically, I get the current x/y of the node I am dropping and than move it using the delta between the dropped node and the node I need to snap it to. The code below is what I used. 0 represents the x coordinate and 1 represents the y coordinate in the array
droppedKromaDevice.setLayoutX(droppedKromaDevice.getLayoutX() - droppedKromaDevice.getBottomAnchorPoint()[0] + parentKromaDevice.getTopAnchorPoint()[0]);
droppedKromaDevice.setLayoutY(droppedKromaDevice.getLayoutY() - droppedKromaDevice.getBottomAnchorPoint()[1] + parentKromaDevice.getTopAnchorPoint()[1]);

Creating a graph with overlapping histograms and saving it to a single file

I am trying to write a Matlab script to analyze two specific sets of data, create histograms for them, and write them to a single file where you can see both histograms overlapped on one plot.
I created a functioning script that created the histogram for 1 set of data that basically went like this:
h1=figure;
hist(data,nbins:;
print(h1,'-dpng','hist.png)
Then I tried to simply add a second line of:
h2=figure;
and changed the print function to include h2. That obviously didn't work. I found that I couldn't have both an h1 and an h2 with the print function.
After searching the internet and looking for ways to get around this I decided to try to use saveas instead. I got to the following:
h=findobj(gca,'Type','patch');
hist(data1,nbins);
hold on;
hist(data2,nbins);
set(h(1),'FaceColor','r','EdgeColor','k');
set(h(2),'FaceColor','b','EdgeColor','k');
saveas(h,'-dpng','hist.png')
But this won't quite work either. I haven't found anything on the Mathworks website that helps me with this problem, and I haven't found anything on any other site either. I am using a Linux computer connecting to a different server via SSH so the only way that I can view plots that I make is by saving them to a file and then opening them. Please let me know if you have any suggestions to accomplish my task as outlined in my first paragraph. Thank you.
One way is to use different axes for different histogram. You can use SUBPLOT for this:
subplot(2,1,1)
hist(data1,nbins);
subplot(2,1,2)
hist(data2,nbins);
Another way is to find a common bins (x) and return the hist output to vectors. Then use BAR function for the plot.
nbins = 20;
x = linspace(min([data1(:);data2(:)]),max([data1(:);data2(:)]),nbins);
h1 = hist(data1, x);
h2 = hist(data2, x);
hb = bar(x,[h1(:),h2(:)],'hist');
% change colors and set x limits
set(hb(1),'FaceColor','r','EdgeColor','k');
set(hb(2),'FaceColor','b','EdgeColor','k');
gap = x(2)-x(1);
xlim([x(1)-gap x(end)+gap])

Resources