Description Usage Arguments Details Value Author(s) See Also Examples
The patternbar_s
function is a tool for creating versatile stacked bar charts
by filling the bars with colors and patterns.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | patternbar_s(
data,
x,
y,
group,
xlab = "",
ylab = "",
label.size = 3.5,
pattern.type,
pattern.line.size = rep(10, length(unique(group))),
pattern.color = rep("black", length(unique(group))),
background.color = rep("white", length(unique(group))),
frame.color = "black",
frame.size = 1,
pixel = 20,
density = rep(12, length(unique(group))),
legend.type = "h",
legend.h = 6,
legend.x.pos = 1.1,
legend.y.pos = 0.49,
legend.w = 0.2,
legend.pixel = 20,
legend.label,
bar.width = 0.9
)
|
data |
the data to be used. |
x |
the variable used on x axis. |
y |
the variable used on y axis. |
group |
the variable used as the second grouping variable on x axis. |
xlab |
a character string to give x axis label. |
ylab |
a character string to give y axis label. |
label.size |
the font size of legend labels shown above the bars. |
pattern.type |
a vector of patterns to be filled in the bars The pattern types include: 'blank', 'bricks', 'vdashes', 'hdashes', 'crosshatch','dots', 'grid','hlines','nelines', 'nwlines', 'vlines', 'waves' and more. |
pattern.line.size |
a vector of numeric values, the line size for the lines/dots of patterns. |
pattern.color |
a vector of colors for the lines/dots of patterns. |
background.color |
a vector of colors to be filled in the bars. |
frame.color |
the color for the borders of bars. |
frame.size |
a numeric value, the line size for the borders of bars. |
pixel |
a numeric value, the pixel resolution of bar chart. |
density |
a numeric vector, the density for the lines/dots of patterns. |
legend.type |
if legend.type='h', the layout of legends is horizontal; if legend.type='v', the layout of legends is vertical. |
legend.h |
a numeric value to change the height of legend boxes. |
legend.x.pos |
a numeric value to change the position of legends on x axis. |
legend.y.pos |
a numeric value to change the position of legends on y axis. |
legend.w |
a numeric value to change the width of legends. |
legend.pixel |
a numeric value to change pixel of legends. |
legend.label |
a vector to name legend labels. |
bar.width |
a numeric value to change the width of the bars. |
patternbar_s
function offers flexible ways of doing stacked bar charts.
A ggplot object.
Chunqiao Luo (chunqiaoluo@gmail.com)
Function imagebar_s
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #Example 1
library(patternplot)
library(png)
library(ggplot2)
data <- read.csv(system.file("extdata", "monthlyexp.csv", package="patternplot"))
x<-data$Location
y<-data$Amount
group<-data$Type
patternbar_s(data,x, y, group,xlab='', ylab='Monthly Expenses, Dollar', label.size=3.5,
pattern.type=c('Unicode_\u266B', 'nwlines', 'bricks'),pattern.line.size=c(10, 5, 5),frame.size=1,
pattern.color=c('blue', 'green', 'white'),background.color=c('white', 'white', 'orange'),pixel=20,
density=c(10, 10, 10),frame.color='black', legend.type='h', legend.h=10, legend.y.pos=0.49,
legend.pixel=10, legend.w=0.25, legend.x.pos=1.1,
legend.label=c("Childcare", "Food", "Housing" ))+scale_y_continuous(limits = c(0, 6800))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.