How to set dimensions of LineSeries - oxyplot

I have a line series that covers data from 1 to 20 along the X axis and 0 to 1 along the Y axis. My problem is that the x axis always starts at 0 and goes to the furthest value and the Y axis starts at 0 but only goes to the furthest value as well. How can I set these dimensions?

So for the Y axis this is what you want
plotModel.Axes.Add(new LinearAxis()
{
Title = "Y axis Name",
Position = AxisPosition.Left,
MinorStep = 0.1,
FilterMinValue = -1,
FilterMaxValue = 1
});
As for the X axis it seems to be more annoying handLabeling seems to be the only way.
plotModel.Axes.Add(new CategoryAxis()
{
Title = "X axis name",
Position = AxisPosition.Bottom,
Labels = {"1","2","3","4","5","6" } // ... upto 20
});
Then every item you add index the value of the Category label.
For example if I want an column of 64 on 3 in X axis then the code would look like this:
var item =new ColumnItem(62, 2); // index 2 being value "3"

Related

How to plot a coordinate graph using plotly.Kt for y=1/x

The goal is to plot the problems with dividing by zero using plotly:
The requirement is to draw a four quadrant coordinate graph and plot towards zero.
For equation y=1/x
x | y
1 | 1
1/2 | 2
1/3 | 3
0 | -
-1/3| -3
-1/2|-2
-1 |-1
So far, I was able to draw the quadrant, but I want to plot the curved path or draw a line around.
fun main() {
val trace1 = Scatter {
x(-2, -1, -0, 1, 2)
y(1, 2, 3, 4, 5)
}
val plot = Plotly.plot {
traces(trace1)
layout {
title = "Vertical and Horizontal Lines Positioned Relative to the Axes"
xaxis {
range = -2.0..2.0
}
yaxis {
range = -9.0..9.0
}
width = 700
height = 500
shape {
type = ShapeType.path
x0 = Value.of(0.5)
y0 = Value.of(2)
x1 = Value.of(1)
y1 = Value.of(1)
line {
color("rgb(50, 171, 96)")
width = 4
dash = Dash.dot
}
}
}
}
plot.makeFile()
}
You can add different lines to each quadrant to draw y=1/x. For example, like this:
val trace1 = Scatter {
val range = -200..1
x.numbers = range.map{ it.toDouble() / 100 }
y.numbers = range.map{ 1 / (it.toDouble() / 100) }
name = "negative"
}
val trace2 = Scatter {
val range = 1..200
x.numbers = range.map{ it.toDouble() / 100 }
y.numbers = range.map{ 1 / (it.toDouble() / 100) }
name = "positive"
}
val plot = Plotly.plot {
traces(trace1, trace2)
...
}
plot.makeFile()
The result looks like this.

Error in sum(x[i:(i + 50)], na.rm = TRUE) : invalid 'type' (character) of argument

I am new in R , and I am trying to do a script to calculate the sliding mean of some data.
This is how my data looks like:
Timestamp Accelerometer X Accelerometer Y Accelerometer Z
1 121219.757080078 -5.66180946541818 8.85684119781125 1.65407075345669
2 121239.288330078 -7.38255951126451 9.4117333531527 1.44410517346543
it has around 6000 rows, and I need to calculate the mean of Accelerometer x, Accelerometer Y, and Accelerometer Z each fifty rows. So from the data of row 1 to 50 I must get the mean of the 3 variables, then from rows 51 to 100, and so on until row 6000.
I tried with (for the first variable):
library(reshape2)
library(reshape)
x <- deadlift$`Accelerometer X`
win.size <- 50
slide <- 50
results <- data.frame(index=numeric(),win.mean=numeric())
i<-1
j<-1
while (i<length(x)) {
win.mean<-sum(x[i:(i+50)],na.rm = TRUE)/win.size
results[j,]<-c(i,win.mean)
i<-i+slide
j<-j+1
}
but I get this message:
Error in sum(x[i:(i + 50)], na.rm = TRUE) :
invalid 'type' (character) of argument
any help?
Thank you.
Problem solved.
the problem was that the object x was created as character. I converted it to numeric with as.numeric.
It worked.
Regards,

Shiny leaflet select input code

I want change circles color of selected region on the map. Need your advise. Please help me to create the right observeEvent for selectInput action. I need the app clear my circles and highlight only selected region with specific pop up.
My data:
Region Pop Latitude Lontitude
1 Cherkasy 1238593 49.444433 32.059767
2 Chernihiv 1040492 51.498200 31.289350
3 Chernivtsi 909081 48.292079 25.935837
4 City of Kyiv 2909491 50.450100 30.523400
5 Dnipro 3244341 48.464717 35.046183
6 Donetsk 4255450 48.015883 37.802850
7 Ivano-Frankivsk 1381014 48.922633 24.711117
8 Kharkiv 2711475 49.993500 36.230383
9 Kherson 1059481 46.635417 32.616867
10 Khmelnytskiy 1291187 49.422983 26.987133
11 Kirovohrad 969662 48.507933 32.262317
12 Kyiv 1732435 50.450100 30.523400
13 Luhansk 2200807 48.574041 39.307815
14 Lviv 2531265 49.839683 24.029717
15 Mykolayiv 1155174 46.975033 31.994583
16 Odesa 2386441 46.482526 30.723310
17 Poltava 1433804 49.588267 34.551417
18 Rivne 1161537 50.619900 26.251617
19 Sumy 1108651 50.907700 34.798100
20 Ternopil 1063264 49.553517 25.594767
21 Vinnytsya 1597683 49.233083 28.468217
22 Volyn 1042218 50.747233 25.325383
23 Zakarpattya 1258507 48.620800 22.287883
24 Zaporizhzhya 1747639 47.838800 35.139567
25 Zhytomyr 1244219 50.254650 28.658667
Code
library(shiny)
library(leaflet)
library(maps)
library(shinythemes)
library(readxl)
UkrStat <- read_excel("D:/My downloads/Downloads/R Studio/UkrStat.xlsx")
ui <- (fluidPage(theme = shinytheme("superhero"),
titlePanel("Map of Ukraine"),
sidebarLayout(
sidebarPanel(
selectInput("region", label = "Region", choices = c("", UkrStat$Region), selected = "City of Kyiv")
),
mainPanel(
leafletOutput("CountryMap", width = 1000, height = 500))
)
))
server <- function(input, output, session){
output$CountryMap <- renderLeaflet({
leaflet() %>% addTiles() %>% addProviderTiles("CartoDB.Positron") %>%
setView(lng = 31.165580, lat = 48.379433, zoom = 6) %>%
addCircles(lng = UkrStat$Lontitude, lat = UkrStat$Latitude, weight = 1, radius = sqrt(UkrStat$Pop)*30, popup = UkrStat$Region)
})
observeEvent(input$region, {
leafletProxy("CountryMap") %>% clearMarkers()
})
}
# Run the application
shinyApp(ui = ui, server = server)
To achieve what you want you need to replace your observeEvent for input$region with the following:
observeEvent(input$region, {
if(input$region != "")
{
leafletProxy("CountryMap") %>% clearShapes()
index = which(UkrStat$Region == input$region)
leafletProxy("CountryMap")%>% addCircles(lng = UkrStat$Lontitude[index], lat = UkrStat$Latitude[index],
weight = 1, radius = sqrt(UkrStat$Pop[index])*30, popup = UkrStat$Region[index])
}
})
Here I am first clearing all the circles. After that I am finding the index for the selected region and getting the corresponding longitude and latitude and adding circles at that position.
Hope it helps!

Processing: conditional to test for variable change

My question pertains to the environment of Processing 2.0.
I need to write a conditional (or set of conditionals) in void draw() that tests if the variable x has increased by 1 or decreased by 1 and adjust the variable y depending on the increase/decrease in x. For example if x decreases 1, y should increase by 10, and if x increases by 1 y should decrease by 10. How would I accomplish this?
The most obvious answer is to try to think of y as a multiple of x plus maybe an offset? So if you have your x going up and down every time you enter the draw() method you should do y = x * 10; or y = 400 + x * 10 if you have an offset (int this case 400) of some sorts...
If you absolutely have to do it like that, then the way is to store the previous value of x and check each at each draw() call. So create a new variable int prevX and in your draw() method do:
y = y + (x-prevX) * 10;
or
int diff = x - prevX;
if(diff == -1) y = y - 10;
else if (diff == 1) y = y + 10;

If statements - certain value or more

I have an app where i want it to only do some thing if the int value is a certain number or above and i cant seem to figure out how to do it, i can do it if it is exactly the amount but not if its more.
For example i have an int value of 0 and its goes up every time you push a button, when it becomes 20 or higher i want it to do something when another button is pressed.
Thanks for he help!
- (IBAction)storeTroll:(id)sender {
if (count == 20) {
trollButton.hidden = NO;
}
}
Operator Description
x == y Returns true if x is equal to y
x > y Returns true if x is greater than y
x >= y Returns true if x is greater than or equal to y
x < y Returns true if x is less than y
x <= y Returns true if x is less than or equal to y
x != y Returns true if x is not equal to y
So, use >= :
- (IBAction)storeTroll:(id)sender {
if (count >= 20) {
trollButton.hidden = NO;
}
}