  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Barchart grouped by variable both count up to 100 percent  » r » Barchart grouped by variable both count up to 100 percent

By : user7455091
Date : November 21 2020, 03:00 PM
The only change is the group_by(Phase) line. code :
``````require(dplyr)
require(ggplot2)

count(Phase = factor(Phase), Activities = factor(Activities)) %>%
group_by(Phase) %>%
mutate(pct = prop.table(n) * 100) %>%
ggplot(aes(x = Phase, y = n, fill = Activities)) +
geom_bar(stat = 'identity', position = 'dodge') +
geom_text(aes(y = n + .2,    # nudge above top of bar
label = paste0(round(pct, 2), '%')),    # prettify
position = position_dodge(width = .9),
size = 3)
`````` ## ggvis side-by-side barchart grouped by second variable

By : user3190424
Date : March 29 2020, 07:55 AM
I wish this helpful for you I don't see an easy way to do this yet. But a work around is to explicitly define your x axis as a combination of your x and fill variables:
code :
``````library(ggivs)
library(dplyr)

steps <-c("A","B","C","D","A","B","C","D")
ratio <-c(1.1,1.5,1.7,1.4,1.5,1.7,1.4,1.9)
feature <-c("cc","cc","cc","cc","ca","ca","ca","ca")
shrink <- data.frame(steps,ratio,feature)

shrink %>%
mutate(steps_feature = factor(paste(steps, feature))) %>%
ggvis(x= ~steps_feature, y= ~ratio, fill = ~feature) %>%
layer_bars(stack = FALSE)
``````
``````library(tidyr)
shrink %>%
ggvis(x = ~ca, y = ~cc, text := ~steps) %>%
layer_text(fontSize := 35)
`````` ## Grouped columns in barchart with variable count of data entries using ios-charts library

By : Frankie Jj
Date : March 29 2020, 07:55 AM
should help you out It is a bug, and, I think you have opened this issue on github, right? Anyway, you should be able to proceed with the fix: https://github.com/danielgindi/ios-charts/pull/248.
if there are two bars in one group, there should be only two dataSets, not 4, and each dataSet has two dataEntries. What you are using has 4 dataSets, and it leads to more space left for each x axis zone, that's why it is not centered. ## Stacked ggplot percent barchart in shiny

By : Jonathan Lloyd
Date : March 29 2020, 07:55 AM
it should still fix some issue The error from your paste0 command comes because it is the last line in the reactive, and thus becomes the return value. Just add a statement return(df) or something equivalent and that will fix that problem.
As for the label positioning, the code is working as designed, you will have to calculate the desired positions for the geom_text and use those coordinates explicitly.That will require you summing up the coordinates for each individual brand segment so you know its left and right positions and can calculate the center. ## How to center stacked percent barchart labels

By : ujjval
Date : March 29 2020, 07:55 AM
hope this fix your issue Here's how to center the labels and avoid plotting labels for small percentages. An additional issue in your data is that you have multiple bar sections for each colour. Instead, it seems to me all the bar sections of a given colour should be combined. The code below uses dplyr instead of plyr to set up the data for plotting:
code :
``````library(dplyr)

# Initial data frame
df <- data.frame(Category, Brand, USD)

# Calculate percentages
df.summary = df %>% group_by(Brand, Category) %>%
summarise(USD = sum(USD)) %>%   # Within each Brand, sum all values in each Category
mutate(percent = USD/sum(USD))
``````
``````ggplot(df.summary, aes(x=reorder(Brand, USD, sum), y=percent, fill=Category)) +
geom_bar(stat="identity", width = .7, colour="black", lwd=0.1) +
geom_text(aes(label=ifelse(percent >= 0.07, paste0(sprintf("%.0f", percent*100),"%"),"")),
position=position_stack(vjust=0.5), colour="white") +
coord_flip() +
scale_y_continuous(labels = percent_format()) +
labs(y="", x="")
``````
``````# Calculate percentages and label positions
df.summary = df %>% group_by(Brand, Category) %>%
summarise(USD = sum(USD)) %>%   # Within each Brand, sum all values in each Category
mutate(percent = USD/sum(USD),
pos = cumsum(percent) - 0.5*percent)
``````
``````ggplot(df.summary, aes(x=reorder(Brand,USD,function(x)+sum(x)), y=percent, fill=Category)) +
geom_bar(stat='identity',  width = .7, colour="black", lwd=0.1) +
geom_text(aes(label=ifelse(percent >= 0.07, paste0(sprintf("%.0f", percent*100),"%"),""),
y=pos), colour="white") +
coord_flip() +
scale_y_continuous(labels = percent_format()) +
labs(y="", x="")
`````` ## R - geom_bar Grouped Barchart with grouped Labels

By : jiebai720
Date : March 29 2020, 07:55 AM
hope this fix your issue zoo::as.yearmon expects %b i.e. the abbreviated month name (e.g. Jan, Feb etc) in the locale of your system.
In this case you seem to be using month in German format but you locale is different. You can check your current setting using
code :
``````Sys.getlocale()
``````
``````Sys.setlocale("LC_TIME", "de_DE")  #Mac
Sys.setlocale("LC_TIME", "German") #Windows
`````` 