How To Draw A Histogram In R
Bones Histogram
library ( plotly ) fig <- plot_ly ( x = ~ rnorm ( 50 ), blazon = "histogram" ) fig Normalized Histogram
library ( plotly ) fig <- plot_ly ( x = ~ rnorm ( 50 ), type = "histogram" , histnorm = "probability" ) fig Specify Binning Function
library ( plotly ) ten = c ( "Apples" , "Apples" , "Apples" , "Organges" , "Bananas" ) y = c ( "v" , "x" , "three" , "10" , "5" ) fig <- plot_ly ( y = y , ten = x , histfunc = 'sum' , type = "histogram" ) fig <- fig %>% layout ( yaxis = listing ( type = 'linear' )) fig Horizontal Histogram
library ( plotly ) fig <- plot_ly ( y = ~ rnorm ( 50 ), type = "histogram" ) fig Overlaid Histograms
fig <- plot_ly ( alpha = 0.6 ) fig <- fig %>% add_histogram ( x = ~ rnorm ( 500 )) fig <- fig %>% add_histogram ( x = ~ rnorm ( 500 ) + one ) fig <- fig %>% layout ( barmode = "overlay" ) fig Stacked Histograms
fig <- plot_ly ( blastoff = 0.half dozen ) fig <- fig %>% add_histogram ( x = ~ rnorm ( 500 )) fig <- fig %>% add_histogram ( x = ~ rnorm ( 500 ) + one ) fig <- fig %>% layout ( barmode = "stack" ) fig Cumulative Histogram
library ( plotly ) fig <- plot_ly ( x = ~ rnorm ( l ), blazon = "histogram" , cumulative = listing ( enabled = TRUE )) fig Share bins between histograms
In this example both histograms take a uniform bin settings using bingroup attribute.
library ( plotly ) fig <- plot_ly ( blazon = 'histogram' , x =~ rnorm ( 100 , five ), bingroup = one ) fig <- fig %>% add_trace ( type = 'histogram' , 10 =~ rnorm ( xx , 5 ), bingroup = ane ) fig <- fig %>% layout ( barmode = "overlay" , bargap = 0.1 ) fig Note that traces on the same subplot, and with the same barmode ("stack", "relative", "group") are forced into the same bingroup, withal traces with barmode = "overlay" and on different axes (of the same centrality type) can have compatible bin settings. Histogram and histogram2d trace tin can share the same bingroup.
library ( plotly ) fig <- plot_ly ( blazon = 'histogram' , x =~ rnorm ( 100 , five )) fig <- fig %>% add_trace ( blazon = 'histogram' , x =~ rnorm ( 20 , 5 )) fig <- fig %>% layout ( barmode = "stack" , bargap = 0.ane ) fig Reference
See https://plotly.com/r/reference/#histogram for more information and chart attribute options!
What About Nuance?
Nuance for R is an open-source framework for building belittling applications, with no Javascript required, and information technology is tightly integrated with the Plotly graphing library.
Learn about how to install Dash for R at https://dashr.plot.ly/installation.
Everywhere in this page that y'all see fig, y'all can brandish the same figure in a Dash for R application by passing it to the figure argument of the Graph component from the built-in dashCoreComponents package similar this:
library ( plotly ) fig <- plot_ly () # fig <- fig %>% add_trace( ... ) # fig <- fig %>% layout( ... ) library ( dash ) library ( dashCoreComponents ) library ( dashHtmlComponents ) app <- Nuance $ new () app $ layout ( htmlDiv ( list ( dccGraph ( figure = fig ) ) ) ) app $ run_server ( debug = True , dev_tools_hot_reload = Imitation )
Source: https://plotly.com/r/histograms/
Posted by: blakeronfiess.blogspot.com

0 Response to "How To Draw A Histogram In R"
Post a Comment