Bokeh line graph showing no y axis values - bokeh

I am trying to run a line plot wit some values and and it is showing the dates on the x axis but nothing in the y axis. I tried
p.figure ( y_range=(0,8000)) and it still didn't work.
This is my code
source=ColumnDataSource(df_ora)
labels = LabelSet(x='DAY', y='LOAD', text='LOAD', level='glyph',
x_offset=5, y_offset=25, source=source, render_mode='canvas')
p = figure(title="Transmission Peak Load
Forecast",x_axis_type="datetime",y_axis_label='Load', plot_width=600,
plot_height=600)
p.line('DAY', 'LOAD', source=source,line_width=1)
p.axis.ticker=DaysTicker(days=np.arange(1,32))
p.add_layout(Title(text="Date", align="center"), "below")
p.add_layout(labels)
p.circle(x=df_ora['DAY'],y=df_ora['LOAD'],size=5)
# output_notebook()
show(p)
So now it shows the days on the bottom, the line plot with the values at the circles, but no range of values in y. I tried to Randge1d(start=0, end=8000), but it still didn't show any numbers in the y axis.

DaysTicker assumes the range values will be timestamps, i.e. milliseconds since epoch. So giving a range (0, 8000) means show the days between 0 and 8000 milliseconds on Jan 1, 1970. There are zero full days in that span.

Related

Date is represented after a gap of 4-5 days on the axis. I want it to be represented in all bars

df = px.data.tips() plotd_2022_dec = px.bar(days_2022_dec, x="Students", y="Date", orientation='h') plotd_2022_dec.update_layout(bargap=0.23,height=724) plotd_2022_dec.show()
How can it be done so that the date is represented on each bars of the plot
see image of plot
what can be done to resolve the isssue

Forecast plot with x axis labels as date

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.

R microbenchmark and autoplot?

I have a couple of questions about microbenchmark and autoplot
Suppose this is my code:
library("ggplot2")
tm <- microbenchmark(rchisq(100, 0),rchisq(100, 1),rchisq(100, 2),rchisq(100, 3),rchisq(100, 5), times=1000L)
autoplot(tm)
What are the units in tm$time? how can i convert that to seconds?
How can I change the marks on the x axis to something like seq(from=0, to=100,by = 5)?
Thanks!
help(microbenchmark) gives:
1. ‘time’ is the measured execution time
of the expression in nanoseconds.
NANOseconds not milliseconds or microseconds.
So divide by 1000000000 to convert to seconds.
And for your second question, my first response is "why?". But its ggplot-based, so you can override bits by adding ggplot things:
autoplot(tm) + scale_y_log10(name="seq(whatever)")
Note the plot is rotated so the x-axis is the y-scale....
I've just thought you really mean "tick marks"? Slightly different but doable, but not really appropriate given the log axis. You can force a non-log axis with specified tick marks:
autoplot(tm) + scale_y_continuous(breaks=seq(0,10000,len=5),name="not a log scale")
You can keep the log scale and set the tick mark points:
autoplot(tm) + scale_y_log10(breaks=c(50,200,500))

R: why is boxplot(x,log="y") different from boxplot(log(x))?

delme <- exp(rnorm(1000,1.5,0.3))
boxplot(delme,log="y")
boxplot(log10(delme))
Why are the whiskers different in this 2 plots?
Thanks
Agus
I would say that in your first plot you just changed the y axis to log, so the values you plot still range between 1 and 10. In this plot the y axis is a log scale. The whiskers on this axis look different because the space between each "tick" (ie axis break) is not constant (there is more space between 2 and 4 than between 10 and 8)
In the second plot, you take the log of the values then plot them, so they range from .2 to 1, and are plotted with a linear y axis.
Look at the summary for both of the normal and log transformed dataframes

Customise x-axis ticks

I have a very large data frame (2 columns) in terms of records. I have plotted the graph in ggplot2. The X axis is the time and the Y axis is values. Over a specific interval from time 50 to 60, I want to make the ticks increments to be smaller such as (50,51,51,53,...59,60). For the rest of the axis, it is fine to have the ticks incremented by 10. So,I would expect to have X-axis values like :
10,20,30,40,50,51,52,53,54,55,56,57,58,58,60,70,80,90,..190,200.
I know, I can modify the ticks through scale_x_continuous by using breaks and minor_breaks. However, I'm not getting the expected output. Here is my try:(note: have created data just for example as my data is very large).
data:
-----
x<-seq(1:200)
y<-seq(51,250,by=1)
df<-data.frame(x=x,y=y)
code:(Update based on #Didzis Elferts suggestion)
-----
ggplot(data=df, aes(x,y))+geom_line(size=1.6)+
scale_x_continuous( breaks=c(10,20,30,40,seq(50,60,by=2),seq(70,200,10))
,minor_breaks=seq(50,60,by=2) )+
+theme(axis.text.x=element_text(size=16),axis.text.y=element_text(size=16))+
+theme(axis.title.x=element_text(size=16),axis.title.y=element_text(size=16))+
+theme(axis.ticks.x = element_line(size = 1))+xlab("Time")+ylab("value")
+theme(axis.ticks.length=unit(0.8,"cm"))
Based on the suggestion below, the only problem now is the values of X-axis during the interval between 50-60 is not clearly appeared.
Any suggestions to make it clear!!
With argument minor_breaks= you set the minor gridlines. To set numbers under the x axis all number should be provided with argument breaks=.
ggplot(data=df, aes(x,y))+geom_line(size=1.6)+
scale_x_continuous(breaks=c(10,20,30,40,seq(50,60,by=1),seq(70,200,10)),
minor_breaks=seq(50,60,by=1))
For the second problem - you set axis.ticks.x=element_line(size=5) inside theme() - that makes your axis ticks wider so they appear as small rectangles. If you want to make axis ticks longer use axis.ticks.length=.
+theme(axis.ticks.length=unit(0.5,"cm"))

Resources