2021/04/19

ggplot2 boxplot to ggplotly

   Package "plotly" provide powerful web interactive tools in chart. ggplot2 is very intuitively for creating charts. Use ggplotly to transform ggplot2 object into plotly object is very convenient. But sometimes it's will make you surprised

For example

```{r}
library(ggplot2)
library(plotly)

df <- diamonds
p <- ggplot(df, aes_string(x = 'carat', y = 'cut')) +
  geom_boxplot()
print(p)

```




But the chart will not as you desire if you use ggplotly

 
```{r}
library(ggplot2)
library(plotly)
df <- diamonds
p <- ggplot(df, aes_string(x = 'carat', y = 'cut')) +
  geom_boxplot()
print(ggplotly(p))
```

 


plotly default set boxplot as verticle, so we use coord_flip to plot horizontal boxplot

```{r}
p <- ggplot(df, aes_string(y = 'carat', x = 'cut')) +
  geom_boxplot()+
  coord_flip()
print(ggplotly(p))

```

for grouped boxplot

```{r}
p <- ggplot(df, aes_string(y = 'carat', x = 'cut', color = 'clarity')) +
  geom_boxplot() +
  coord_flip()
print(p)
```


 

use ggplotly get stacked boxplot

```{r}
p <- ggplot(df, aes_string(y = 'carat', x = 'cut', color = 'clarity')) +
  geom_boxplot() +
  coord_flip()
print(ggplotly(p))
```

fine tune ploty layout:

```{r}
p <- ggplot(df, aes_string(y = 'carat', x = 'cut', color = 'clarity')) +
  geom_boxplot() +
  coord_flip()
print(ggplotly(p) %>% layout(boxmode='group'))
```




 

2016/12/27

Color Ramping using linear approximation

R colorRAmpPalette method with linear approximation: Input C1=(r1,g1,b1), C2=(r2,g2,b2), C3=(r3,g3,b3) and k as number of colors to generate Idea: A walk from C1 to C3 passing through C2 with equal steps. Implement The result color list denote by RC Step1 : the first half colors list distance for one step from C1 to C2 denoted by D1: (C2-C1)/((k-1)/2) RC = C1 + 1:int(k/2) * D1 Step 2: if k is odd, add C2 into this list RC = RC + C2 Step 3: the other half color list distance for one step from C2 to C3 denoted by D2: (C3-C2)/((k-1)/2) RC = RC + (C2 + 1:int(k/2) * D2) Step 4: All the element in RC must between 0 and 255

2015/08/19

updateusr method for better barplot with lines/points

When using barplot with add y2 axis for lines or points by par(new=TRUE)  as show in the example code usually get shifted.

The updateusr method from Greg Snow's TeachingDemos package is a great solution for this problem. The idea behind updateusr is define new plot region according to the ratio of one unit in each axis.

The code:


Example code:(add space 8/20)


Result:

2014/12/08

Error: Package 'XXX' was build before 3.x.x: please re-install it

For install new package which previous install use different R version cause the error:
"Error: Package 'XXX' was build before 3.x.x: please re-install it"


solution:
update.packages(checkBuilt = TRUE, ask = FALSE)

for user privilege issue:
use SUDO R, then update.packages(checkBuilt = TRUE, ask = FALSE)

Reference:
https://stackoverflow.com/questions/16987948/causes-of-error-package-was-built-before-3-0-0-please-re-install-it

2013/08/13

wafer map pattern recognization by fingerprint matching/DNA sequence matching method?

寫下來才不會又忘了 wafer map --> whole fingerprint/total DNA sequence pattern --> partial fingerprint/partial DNA sequence Q1: how to define pattern character as fingerprint's character(minutia/ridge points...) encoding wafer map pattern as DNA sequence Q2: which algorithm to apply? Reference: BFAST Fingerprint Recognition Algorithms for Partial and Full Fingerprints

2012/08/12

Boxplot in R

boxplot.stats for calculating.
the argument coef for multuplier of the IQR. 0 for extream data points in data

returning statistics are lower whisker, P25, median,P75, upper whisker

 

2012/05/31

Wave Chart

The bar plot always start at line 0, therefore use xlim for located the barplot at different x-axis position.
The code:

TO DO: add lines for input statistics

Reference : Quantile regression Chart by Philippe Grosjean, http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=109

CC Copyright

創用 CC 授權條款
本著作由Chunhung Chou製作,以創用CC 姓名標示-相同方式分享 3.0 Unported 授權條款釋出。