Both my X and Y axis are coming in form of 2.000e+7 and 1.5040e+7.
X axis is datetime like 2017-08-02 10:20:37.260
and Y axis should have integer values like 5000.
How can I correct this?enter image description here
plot = figure(plot_width=800, plot_height=450, tools=[hover, TOOLS],
title='Order/Execution Snapshot with Price Levels',
x_axis_label='Date', y_axis_label='Price',x_axis_type="datetime")
X axis type as datetime helped solving the problem.
Related
I'm trying to put a legend on a line graph using legend(x,y, legend=c("","").... etc. I've changed the date to numeric data and used that for x and it plots, so I know the rest of its right. but when x is a date I'm not sure what to use for x to get the legend to show on the graph.
thanks
I have a dataset like revenue and date.
I used arima to plot the data.
ts_data = ts(dataset$Revenue,frequency = 7)
arima.ts = auto.arima(ts_data)
pred = forecast(arima.ts,h=30)
plot(pred,xaxt="n")
When I plot the data, it produces plot like below.
My expectations are below,
I need to display values in Million for predicted values like 13.1M.
I need to show x-axis as date instead of data points numbers.
I tried several links but couldn't crack it. Below are the experiments I made,
Tried with start date and end date in ts_data that also doesnt work.My start date is "2019-09-27" and end date is "2020-07-02"
tried wit axis_date in plot function that also doesnt work.
Please help me to crack the same.
Thanks a lot.
You can specify axis tick values and labels with axis()
plot(pred,xaxt="n", yaxt="n") # deactivate x and y axis
yl<-seq(-5000000,15000000,by=5000000) # position of y-axis ticks
axis(2, at=yl, label=paste(yl/1000000, "M")) # 2 = left axis
You can specify the desired position of y axis ticks with at and the labels to be associated with label. In order to obtain the values like 10 M I have used the function paste to join the numbers with the letter M.
You could use the same method also for x-axis, even tough more efficient methods probably exist. Not having the specific data available I have used a generic spacing and labels only to give you the idea. Once you have set the desired position you can generate the sequence of dates associated with it (to generate a sequence of dates see https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/seq.Date)
axis(1, at=seq(1,40,by=1), label=seq(as.Date("2019-09-27"),as.Date("2020-07-02"),by="week")) # 1 = below axis
You can also change the format of the dates displayed with format() for example label=format(vector_of_date, "%Y-%b-%d") to have year-month(in letter)-day.
I'm using the rgl package in r to plot some data. As done here:
http://www.r-bloggers.com/creating-3d-geographical-plots-in-r-using-rgl/
For some reason the scale does not align with the graph.
I changed the scale of the X and Z axis to increase the relief, which I initially thought was causing the issue, but in the example below, even if I change 0.02 to 1 the issue occurs.
library(rgl)
rdata <- c(0.8926,0.8986,0.9478,0.9672,0.916,0.912,0.9324,0.9532,0.9488,0.9376,0.921,0.927,0.9728,0.956,0.9318,0.9202)
labs <-c(100,200,500,1000)
rmatrix <- matrix(rdata, nrow=4,ncol=4,)
dimnames(rmatrix) <- list(labs,labs)
y <- as.matrix(rmatrix)
x <- 0.02*(1:nrow(y))
z <- 0.02*(1:ncol(y))
rgl.surface(x, z, y, color="red", back="lines")
axis3d('x--', labels=row.names(rmatrix),color="black")
Why is this happening?
Thanks for your help!
Mat
Without supplying a value to the labels argument in axis3d, I get an axis with six tick marks. Since you supply a vector with only four values to the labels argument, it looks like axis3d recycles those values to cover all the tick marks.
Tell axis3d at what data values you'd like to place the tick marks by supplying a value to the at argument:
axis3d('x--', at = x, labels=row.names(rmatrix),color="black")
p.s. I had to add the following line before rgl.surface() to avoid getting a segfault
rgl.open()
I have a vector of values: b=read.csv('https://dl.dropbox.com/u/22681355/b.csv')
I would like to plot them with having values 1:2000 on the x-axis representing time and the values of the vector on the y axis.
When I plot them using hist(b) I get the opposite thing with values from 1:2000 on the y axis and the actual values on the x.
How can I reverse this?
Try barplot(b) or plot(b,type="b") instead.
(Your link doesn't work for me.)
There are two continuous variables (A and B) in my data. I want to make a scatter plot with a regression line in R. I think this is easy. But how can I make different scales (interval) for A on X axis and for B on y axis? For instance, A on X axis: 2, 4, 6, 8, 10, the interval is 2. How can I change it to: 1,2,3,4,5,6,7,8,9,10 where the interval is 1. It is similar for y axis.
Thanks a lot!
There are good instructions at Robert Kabacoff's site. In a nutshell, you could use code such as:
z = c(1:10)
plot (A,B) #add whatever specifications you need
axis (1, at=z, labels=z) #1 indicates the lower horizontal axis; 1=bottom, 2=left, 3=top, 4=right