मैं ggplot में प्रत्येक कॉलम पर टेक्स्ट सेट करना चाहता हूं और वे पूरी तरह से जुड़ रहे हैं
यह मेरा कोड है
set.seed(1)
gg <-
iris[sample(300, 50), ] %>%
ggplot(aes(Species, Sepal.Length, label = Sepal.Length, fill = as.factor(Sepal.Width > 3))) +
geom_col(position = "dodge2") +
geom_text(position=position_dodge(width = .7),
vjust=-0.25)
ggplotly(gg)
0
Cauder
20 अक्टूबर 2020, 03:16
1 उत्तर
सबसे बढ़िया उत्तर
हो सकता है कि मैं geom_col()
और geom_text()
में समान स्थिति शैली का उपयोग करने का सुझाव दूं:
library(plotly)
library(ggplot2)
set.seed(1)
#Plot
gg <-
iris[sample(300, 50), ] %>%
ggplot(aes(Species, Sepal.Length, label = Sepal.Length, fill = as.factor(Sepal.Width > 3))) +
geom_col(position = position_dodge2(0.9)) +
geom_text(position=position_dodge2(width = .9),
vjust=-0.5)
#Transform
ggplotly(gg)
आउटपुट:
साझा डेटा के साथ, इसे आज़माएं, आपको लेबल को चकमा देने के लिए दिनांक को प्रारूपित करना होगा:
library(dplyr)
library(ggplot2)
library(plotly)
#Code
gg <- df %>%
mutate(first_month=factor(format(first_month,'%b-%m'),
levels = unique(format(first_month,'%b-%m')),
ordered = T)) %>%
ggplot(aes(x=first_month, y=customers,
label = customers, fill = plan_id,group=plan_id)) +
geom_bar(stat='identity',position = 'dodge')+
geom_text(aes(group=plan_id),position = position_dodge(0.9),vjust = -0.5)
#Plot 2
ggplotly(gg)
आउटपुट:
1
Duck
20 अक्टूबर 2020, 18:02