diff --git a/doc/filters.texi b/doc/filters.texi
index 93cdad8b41c68335876c15161c95674ce40d730f..efadaf19dc0cdf2cd0d6e38c01260356cb061efd 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -4698,7 +4698,7 @@ It accepts the following values:
 @item levels
 standard histogram that display color components distribution in an image.
 Displays color graph for each color component. Shows distribution
-of the Y, U, V, A or G, B, R components, depending on input format,
+of the Y, U, V, A or R, G, B components, depending on input format,
 in current frame. Bellow each graph is color component scale meter.
 
 @item color
diff --git a/libavfilter/vf_histogram.c b/libavfilter/vf_histogram.c
index 8a98bc7367d622a2320d0f32da421e57d6159ea0..273d03b7e1c2f9ab369547192aff22dcbb02ced4 100644
--- a/libavfilter/vf_histogram.c
+++ b/libavfilter/vf_histogram.c
@@ -248,12 +248,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     switch (h->mode) {
     case MODE_LEVELS:
         for (k = 0; k < h->ncomp; k++) {
+            const int p = h->desc->comp[k].plane;
             int start = k * (h->level_height + h->scale_height) * h->display_mode;
             double max_hval_log;
             unsigned max_hval = 0;
 
             for (i = 0; i < in->height; i++) {
-                src = in->data[k] + i * in->linesize[k];
+                src = in->data[p] + i * in->linesize[p];
                 for (j = 0; j < in->width; j++)
                     h->histogram[src[j]]++;
             }
@@ -275,11 +276,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
                         for (l = 0; l < h->ncomp; l++)
                             out->data[l][(j + start) * out->linesize[l] + i] = h->fg_color[l];
                     } else {
-                        out->data[k][(j + start) * out->linesize[k] + i] = 255;
+                        out->data[p][(j + start) * out->linesize[p] + i] = 255;
                     }
                 }
                 for (j = h->level_height + h->scale_height - 1; j >= h->level_height; j--)
-                    out->data[k][(j + start) * out->linesize[k] + i] = i;
+                    out->data[p][(j + start) * out->linesize[p] + i] = i;
             }
 
             memset(h->histogram, 0, 256 * sizeof(unsigned));