鉴于此代码:
Example.Data<- data.frame(matrix(vector(), 0, 3, dimnames=list(c(), c("Value", "Variable", "Fill"))), stringsAsFactors=F)
Example.Data[1, ] <- c(45, 'Horizontal Pattern','Horizontal Pattern' )
Example.Data[2, ] <- c(65, 'Vertical Pattern','Vertical Pattern' )
Example.Data[3, ] <- c(89, 'Mesh Pattern','Mesh Pattern' )
Example.Data[4,] <- c(20, 'Diagonal Pattern','Diagonal Pattern' )
HighlightDataVert<-Example.Data[2, ]
HighlightHorizontal<-Example.Data[1, ]
HighlightMesh<-Example.Data[3, ]
HighlightHorizontal$Value<-as.numeric(HighlightHorizontal$Value)
Example.Data$Value<-as.numeric(Example.Data$Value)
Example.Data$Variable = Relevel(Example.Data$Variable, ref = c("Horizontal Pattern","Vertical Pattern","Mesh Pattern","Diagonal Pattern"))
example_plot<-ggplot(Example.Data, aes(x=Variable, y=Value, fill=Fill)) + theme_bw() + #facet_wrap(~Product, nrow=1)+ #Ensure theme_bw are there to create borders
theme(legend.position = "none")+
scale_fill_grey(start=.4)+
#scale_y_continuous(limits = c(0, 100), breaks = (seq(0,100,by = 10)))+
geom_bar(position=position_dodge(.9), stat="identity", colour="black", legend = FALSE, width=0.333333333)
如何在上面的width
中返回geom_bar
(0.3333333)的输入值?
我可以按如下方式打印position
:
contents_struct_of_layers = capture.output(str(example_plot$layers))
#splits width lines into list
split_string<-as.list(strsplit(contents_struct_of_layers[39], " ")[[1]])
input_position_dodge<-as.numeric(split_string[10])
input_position_dodge
但在审核example.plot
的内容后,我无法找到geom_bar
position
的相应值。
您可以使用以下代码查看example.plot
及其各种组件的结构:
str(example_plot$layers)
或
STR(example_plot $主题)
等
非常感谢任何帮助。
答案 0 :(得分:2)
您可以在example_plot$layers[[1]]$geom_params$width