所以,我尝试使用facet_wrap 创建一个绘图。 但是,我希望分面标签位于图的右侧,而不是位于图的顶部。
这是我的代码:
library(ggplot2)
# Create the scatter plot with facets for Species
plot <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point(size = 3) + # Scatter plot with larger points
facet_wrap(~ Species, ncol = 1) + # Facet by Species in rows (to position labels on the right)
labs(title = "Sepal Length vs Sepal Width by Species",
x = "Sepal Length",
y = "Sepal Width") +
theme_minimal() +
theme(
legend.position = "none",
strip.text.y = element_text(size = 12, angle = 0), # Facet labels on the right side
strip.placement = "outside", # Place facet labels outside the plot area
strip.background = element_blank(), # Remove background for clarity
panel.spacing = unit(1, "lines"), # Adjust spacing between panels
axis.title.y = element_blank(), # Remove y-axis title for clarity
axis.text.y = element_blank() # Remove y-axis text for clarity
)
print(plot)
提前致谢!
您可以通过设置
strip.position = 'right'
来重新定位小面条
library(ggplot2)
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point(size = 3) + # Scatter plot with larger points
facet_wrap(~ Species, ncol = 1,
strip.position = 'right') + # Facet by Species in rows (to position labels on the right)
labs(title = "Sepal Length vs Sepal Width by Species",
x = "Sepal Length",
y = "Sepal Width") +
theme_minimal() +
theme(
legend.position = "none",
strip.text.y = element_text(size = 12, angle = 0), # Facet labels on the right side
strip.placement = "outside", # Place facet labels outside the plot area
strip.background = element_blank(), # Remove background for clarity
panel.spacing = unit(1, "lines"), # Adjust spacing between panels
axis.title.y = element_blank(), # Remove y-axis title for clarity
axis.text.y = element_blank() # Remove y-axis text for clarity
)